import { initAuth0 , WithPageAuthRequiredOptions , PageRoute , } from '@auth0/nextjs-auth0' ; import getConfig from 'next/config' ; import { GetServerSidePropsContext } from 'next' ; const { serverRuntimeConfig } = getConfig ( ) ; const config = serverRuntimeConfig as { sessionKeys : string [ ] ; sessionVersion : string ; siteBaseUrl : string ; identityBasePath : string ; auth0 : { domain : string ; clientID : string ; clientSecret : string ; } ; remoteApi : { host : string ; apiKey : string ; } ; } ; const identityApiScopes = [ 'create:requests' , 'delete:patron' , 'read:user' , 'read:requests' , 'update:email' , 'update:password' , ] ; const utilityScopes = [ 'openid' , 'offline_access' , ] ; const profileScopes = [ 'profile' , 'email' , 'weco:patron_barcode' ] ; const identityAuthorizationParams = { audience : config . remoteApi . host , scope : [ ... utilityScopes , ... profileScopes , ... identityApiScopes ] . join ( ' ' ) , } ; const ONE_HOUR_S = 60 * 60 ; const ONE_DAY_S = 24 * ONE_HOUR_S ; const auth0 = initAuth0 ( { secret : config . sessionKeys , issuerBaseURL : `https://${ config . auth0 . domain }` , baseURL : config . siteBaseUrl + config . identityBasePath , clientID : config . auth0 . clientID , clientSecret : config . auth0 . clientSecret , authorizationParams : { response_type : 'code' , ... identityAuthorizationParams , } , routes : { postLogoutRedirect : config . siteBaseUrl , } , session : { rolling : true , absoluteDuration : 7 * ONE_DAY_S , rollingDuration : 8 * ONE_HOUR_S , name : `wecoIdentitySession_${ config . sessionVersion }` , } , } ) ; export const withPageAuthRequiredSSR = < P > ( opts ? ) : PageRoute < P > => ( ctx ) => auth0 . withPageAuthRequired < P > ( { ... opts , returnTo : config . identityBasePath + ( opts . returnTo ?? ctx . resolvedUrl ) , } ) ( ctx ) ; export default auth0 ;