@zitadel/react
Version:
Wraps oidc-client-ts to provide a simple interface for ZITADEL
36 lines (35 loc) • 1.66 kB
JavaScript
import { UserManager, WebStorageStateStore, } from "oidc-client-ts";
export function createZitadelAuth(zitadelConfig) {
var _a, _b, _c, _d, _e, _f;
const authConfig = {
authority: `${zitadelConfig.authority}`,
client_id: `${zitadelConfig.client_id}`,
redirect_uri: `${(_a = zitadelConfig.redirect_uri) !== null && _a !== void 0 ? _a : "http://localhost:3000/callback"}`,
response_type: (_b = zitadelConfig.response_type) !== null && _b !== void 0 ? _b : "code",
scope: (_c = zitadelConfig.scope) !== null && _c !== void 0 ? _c : `openid profile email ${zitadelConfig.project_resource_id
? `urn:zitadel:iam:org:project:id:${zitadelConfig.project_resource_id}:aud urn:zitadel:iam:org:projects:roles`
: ""}`,
prompt: (_d = zitadelConfig.prompt) !== null && _d !== void 0 ? _d : "",
post_logout_redirect_uri: `${(_e = zitadelConfig.post_logout_redirect_uri) !== null && _e !== void 0 ? _e : "http://localhost:3000/"}`,
response_mode: (_f = zitadelConfig.response_mode) !== null && _f !== void 0 ? _f : "query",
disablePKCE: zitadelConfig.disablePKCE,
extraQueryParams: zitadelConfig.extraQueryParams,
};
const userManager = new UserManager({
userStore: new WebStorageStateStore({ store: window.localStorage }),
loadUserInfo: true,
...authConfig,
});
const authorize = () => {
return userManager.signinRedirect();
};
const signout = () => {
return userManager.signoutRedirect();
};
const oidc = {
authorize,
signout,
userManager,
};
return oidc;
}