import { UserManager, WebStorageStateStore } from 'oidc-client-ts'; // 创建存储配置的函数,避免 SSR 问题 const createUserStore = () => { if (typeof window !== 'undefined' && window.localStorage) { return new WebStorageStateStore({ store: window.localStorage }); } return undefined; }; // OIDC 客户端配置 export const oidcConfig = { authority: 'http://localhost:3000/oidc', // 后端OIDC provider地址 client_id: 'demo-client', client_secret: 'demo-client-secret', redirect_uri: 'http://localhost:3001/auth/callback', post_logout_redirect_uri: 'http://localhost:3001', response_type: 'code', scope: 'openid profile email', automaticSilentRenew: true, includeIdTokenInSilentRenew: true, revokeTokensOnSignout: true, ...(typeof window !== 'undefined' && { userStore: createUserStore() }), }; // 创建用户管理器实例 export const userManager = typeof window !== 'undefined' ? new UserManager(oidcConfig) : null; // OIDC 相关的URL export const oidcUrls = { login: `${oidcConfig.authority}/auth`, logout: `${oidcConfig.authority}/logout`, token: `${oidcConfig.authority}/token`, userinfo: `${oidcConfig.authority}/userinfo`, };