38 lines
842 B
JavaScript
38 lines
842 B
JavaScript
import {
|
|
ZitadelAuth
|
|
} from "./chunk-NFH7JLJM.js";
|
|
|
|
// src/adapters/svelte.ts
|
|
var authInstance = null;
|
|
function createZitadelHandle(config) {
|
|
const auth = new ZitadelAuth(config);
|
|
authInstance = auth;
|
|
auth.init().then(() => {
|
|
if (!auth.isAuthenticated && !auth.error) {
|
|
auth.login();
|
|
}
|
|
});
|
|
return {
|
|
subscribe: (cb) => {
|
|
cb({
|
|
isAuthenticated: auth.isAuthenticated,
|
|
isLoading: auth.isLoading,
|
|
user: auth.user,
|
|
error: auth.error
|
|
});
|
|
return auth.onAuthChange(cb);
|
|
},
|
|
login: () => auth.login(),
|
|
logout: () => auth.logout(),
|
|
fetch: (url, init) => auth.fetch(url, init)
|
|
};
|
|
}
|
|
function getAuth() {
|
|
if (!authInstance) throw new Error("Call createZitadelHandle() before getAuth()");
|
|
return authInstance;
|
|
}
|
|
export {
|
|
createZitadelHandle,
|
|
getAuth
|
|
};
|