Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function checkUser (
setUserCallback?: (me: $rdf.NamedNode | null) => T
): Promise<$rdf.NamedNode | T> {
// Check to see if already logged in / have the WebID
const me = defaultTestUser()
if (me) {
return Promise.resolve(setUserCallback ? setUserCallback(me) : me)
}
// doc = kb.any(doc, ns.link('userMirror')) || doc
return solidAuthClient
.currentSession()
.then(webIdFromSession)
.catch(err => {
console.log('Error fetching currentSession:', err)
})
.then(webId => {
// if (webId.startsWith('dns:')) { // legacy rww.io pseudo-users
// webId = null
// }
const me = saveUser(webId)
if (me) {
console.log(`(Logged in as ${me} by authentication)`)
}
return setUserCallback ? setUserCallback(me) : me
async getWebId() {
const session = await auth.currentSession();
if (!session)
throw new Error('Cannot resolve user path: no user logged in');
return session.webId;
}
}
checkSession: async function() {
var sess = await solid.currentSession()
if(!sess){
this.webId = undefined
return false;
}
this.webId = sess.webId
return { webId : sess.webId }
},
popupLogin: async function() {
box.refresh = function () {
solidAuthClient.currentSession().then(
session => {
if (session && session.webId) {
me = $rdf.sym(session.webId)
} else {
me = null
}
if ((me && box.me !== me.uri) || (!me && box.me)) {
widgets.clearElement(box)
if (me) {
box.appendChild(logoutButton(me, options))
} else {
box.appendChild(signInOrSignUpBox(dom, setIt, options))
}
}
box.me = me ? me.uri : null
},