[FA-misc] Astro migration works, probably want to touchup the frontend but that can be in Phase 4
This commit is contained in:
35
fictionarchive-web-astro/src/lib/auth/oidcConfig.ts
Normal file
35
fictionarchive-web-astro/src/lib/auth/oidcConfig.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { UserManager, WebStorageStateStore, type UserManagerSettings } from 'oidc-client-ts';
|
||||
|
||||
const authority = import.meta.env.PUBLIC_OIDC_AUTHORITY;
|
||||
const clientId = import.meta.env.PUBLIC_OIDC_CLIENT_ID;
|
||||
const redirectUri = import.meta.env.PUBLIC_OIDC_REDIRECT_URI;
|
||||
const postLogoutRedirectUri = import.meta.env.PUBLIC_OIDC_POST_LOGOUT_REDIRECT_URI ?? redirectUri;
|
||||
const scope = import.meta.env.PUBLIC_OIDC_SCOPE ?? 'openid profile email';
|
||||
|
||||
export const isOidcConfigured =
|
||||
Boolean(authority) && Boolean(clientId) && Boolean(redirectUri);
|
||||
|
||||
function buildSettings(): UserManagerSettings | null {
|
||||
if (!isOidcConfigured) return null;
|
||||
|
||||
return {
|
||||
authority: authority!,
|
||||
client_id: clientId!,
|
||||
redirect_uri: redirectUri!,
|
||||
post_logout_redirect_uri: postLogoutRedirectUri,
|
||||
response_type: 'code',
|
||||
scope,
|
||||
loadUserInfo: true,
|
||||
automaticSilentRenew: true,
|
||||
userStore:
|
||||
typeof window !== 'undefined'
|
||||
? new WebStorageStateStore({ store: window.localStorage })
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export const userManager = (() => {
|
||||
const settings = buildSettings();
|
||||
if (!settings) return null;
|
||||
return new UserManager(settings);
|
||||
})();
|
||||
Reference in New Issue
Block a user