in htdocs/js/selfserve.js [95:128]
async function OAuthGate(callback) {
const QSDict = new URLSearchParams(document.location.search);
if (QSDict.get('action') === 'oauth') { // OAuth callback?
const OAuthResponse = await GET(`/api/auth?${QSDict.toString()}`);
if (OAuthResponse.status === 200) {
if (sessionStorageSupported()) {
const OriginURL = window.sessionStorage.getItem('asp_origin');
// Do we have a stored URL to redirect back to, now that OAuth worked?
if (OriginURL) {
window.sessionStorage.removeItem('asp_origin');
document.location.href = OriginURL;
}
return;
}
} else {
// Something went wrong. For now, just spit out the response as an alert.
toast(await OAuthResponse.text());
}
}
const session = await GET('/api/auth');
if (session.status === 404) { // No session set for this client yet, run the oauth process
if (sessionStorageSupported()) {
window.sessionStorage.setItem('asp_origin', document.location.href); // Store where we came from
}
// Construct OAuth URL and redirect to it
let origin = encodeURIComponent(document.location.href);
document.location.href = `https://${document.location.hostname}/api/auth?login=${origin}`;
} else if (session.status === 200) { // Found a working session
const preferences = await session.json();
if (callback) callback(preferences, QSDict);
} else { // Something went wrong on the backend, spit out the error msg
toast(await session.text());
}
}