37 lines
830 B
JavaScript
37 lines
830 B
JavaScript
import {
|
|
ZitadelAuth
|
|
} from "./chunk-NFH7JLJM.js";
|
|
|
|
// src/adapters/angular.ts
|
|
var AUTH_INSTANCE_KEY = "__kuns_zitadel_auth__";
|
|
function provideZitadelAuth(config) {
|
|
const auth = new ZitadelAuth(config);
|
|
globalThis[AUTH_INSTANCE_KEY] = auth;
|
|
return {
|
|
provide: "KUNS_ZITADEL_AUTH",
|
|
useValue: auth
|
|
};
|
|
}
|
|
function getAuthInstance() {
|
|
const auth = globalThis[AUTH_INSTANCE_KEY];
|
|
if (!auth) throw new Error("Call provideZitadelAuth() before using zitadelGuard()");
|
|
return auth;
|
|
}
|
|
function zitadelGuard() {
|
|
let initPromise = null;
|
|
return async () => {
|
|
const auth = getAuthInstance();
|
|
if (!initPromise) {
|
|
initPromise = auth.init();
|
|
}
|
|
await initPromise;
|
|
if (auth.isAuthenticated) return true;
|
|
auth.login();
|
|
return false;
|
|
};
|
|
}
|
|
export {
|
|
provideZitadelAuth,
|
|
zitadelGuard
|
|
};
|