28 lines
749 B
TypeScript
28 lines
749 B
TypeScript
import { userManager } from './oidc';
|
|
|
|
const KEY = 'pm.returnUrl';
|
|
let redirecting = false;
|
|
|
|
export function saveReturnUrl(path: string): void {
|
|
if (path === '/login' || path.startsWith('/auth/callback')) return;
|
|
sessionStorage.setItem(KEY, path);
|
|
}
|
|
|
|
export function consumeReturnUrl(): string {
|
|
const v = sessionStorage.getItem(KEY) ?? '/';
|
|
sessionStorage.removeItem(KEY);
|
|
return v;
|
|
}
|
|
|
|
export async function triggerLoginRedirect(): Promise<void> {
|
|
if (redirecting) return;
|
|
redirecting = true;
|
|
saveReturnUrl(window.location.pathname + window.location.search);
|
|
try {
|
|
await userManager.removeUser();
|
|
} catch (err) {
|
|
console.error('OIDC: removeUser before redirect failed', err);
|
|
}
|
|
await userManager.signinRedirect();
|
|
}
|