import { UserManager } from "oidc-client-ts";
import { AuthProviderProps } from "react-oidc-context";

const ORIGIN_URI = globalThis?.window?.location.origin;
const REDIRECT_URI = `${ORIGIN_URI}/auth/callback`;

const userConfig: AuthProviderProps = {
  authority: process.env.NEXT_PUBLIC_AUTHORITY!,
  client_id: process.env.NEXT_PUBLIC_CLIENT_ID!,
  client_secret: process.env.NEXT_PUBLIC_CLIENT_SECRET!,
  redirect_uri: REDIRECT_URI,
  response_type: "code",
  includeIdTokenInSilentRenew: true,
  automaticSilentRenew: false, //TODO: Dit moet dus denk ik wel gewoon aan?
  scope: "openid profile email offline_access", //TODO: Iets met scopes.
  accessTokenExpiringNotificationTimeInSeconds: 5 * 60,
  loadUserInfo: true,
  post_logout_redirect_uri: ORIGIN_URI,
  response_mode: "query",
};

export const userManager = new UserManager(userConfig);
export const oidcConfig = { ...userConfig, userManager };
