Skip to content

Commit

Permalink
Move solid-auth-client resolution to webpack.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Jan 3, 2019
1 parent d850133 commit 2421d66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ const Uri = require('./uri')
const Util = require('./util')
const serialize = require('./serialize')

// This is a special fetch withich does OIDC auth, catching 401 errors
const auth = require('solid-auth-client')
const fetch = auth ? auth.fetch : (a, b) => window.fetch(a, b)
// This is a special fetch which does OIDC auth, catching 401 errors
const { fetch } = require('solid-auth-client')

const Parsable = {
'text/n3': true,
Expand Down
11 changes: 8 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ module.exports = (env, args) => {
},
plugins: [
new WrapperPlugin({
// Ensure `solid` namespace exists for externals
header: `if (typeof window !== 'undefined' && !window.solid)
window.solid = {};`
// Fall back to window.fetch when solid-auth-client is not present,
// so rdflib.js can still work outside of Solid
header: `if (typeof window !== 'undefined') {
if (!window.solid)
window.solid = {}
if (!window.solid.auth)
window.solid.auth = { fetch: (a, b) => window.fetch(a, b) }
}`
})
],
optimization: {
Expand Down

0 comments on commit 2421d66

Please sign in to comment.