fix: commit vendored @kuns/zitadel-auth dist (was excluded by dist/ gitignore)
This commit is contained in:
51
vendor/zitadel-auth/dist/react.js
vendored
Normal file
51
vendor/zitadel-auth/dist/react.js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
ZitadelAuth
|
||||
} from "./chunk-NFH7JLJM.js";
|
||||
|
||||
// src/adapters/react.tsx
|
||||
import {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
useSyncExternalStore
|
||||
} from "react";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
var AuthContext = createContext(null);
|
||||
function ZitadelProvider({ children, ...config }) {
|
||||
const [auth] = useState(() => new ZitadelAuth(config));
|
||||
const [ready, setReady] = useState(false);
|
||||
useEffect(() => {
|
||||
auth.init().then(() => {
|
||||
setReady(true);
|
||||
if (!auth.isAuthenticated && !auth.error) {
|
||||
auth.login();
|
||||
}
|
||||
});
|
||||
}, [auth]);
|
||||
if (!ready) return null;
|
||||
return /* @__PURE__ */ jsx(AuthContext.Provider, { value: auth, children });
|
||||
}
|
||||
function useAuth() {
|
||||
const auth = useContext(AuthContext);
|
||||
if (!auth) throw new Error("useAuth must be used within a ZitadelProvider");
|
||||
const state = useSyncExternalStore(
|
||||
(cb) => auth.onAuthChange(cb),
|
||||
() => ({
|
||||
isAuthenticated: auth.isAuthenticated,
|
||||
isLoading: auth.isLoading,
|
||||
user: auth.user,
|
||||
error: auth.error
|
||||
})
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
login: () => auth.login(),
|
||||
logout: () => auth.logout(),
|
||||
fetch: (url, init) => auth.fetch(url, init)
|
||||
};
|
||||
}
|
||||
export {
|
||||
ZitadelProvider,
|
||||
useAuth
|
||||
};
|
||||
Reference in New Issue
Block a user