import { CookieStore , TransientStore , clientFactory , loginHandler as baseLoginHandler , logoutHandler as baseLogoutHandler , callbackHandler as baseCallbackHandler } from './auth0-session' ; import { handlerFactory , callbackHandler , loginHandler , logoutHandler , profileHandler , Handlers , HandleAuth , HandleLogin , HandleProfile , HandleLogout , HandleCallback , LoginOptions , LogoutOptions , GetLoginState , ProfileOptions , CallbackOptions , AfterCallback , AfterRefetch } from './handlers' ; import { sessionFactory , accessTokenFactory , SessionCache , GetSession , GetAccessToken , Session , AccessTokenRequest , GetAccessTokenResult , Claims } from './session/' ; import { withPageAuthRequiredFactory , withApiAuthRequiredFactory , WithApiAuthRequired , WithPageAuthRequired , GetServerSidePropsResultWithSession , WithPageAuthRequiredOptions , PageRoute } from './helpers' ; import { InitAuth0 , SignInWithAuth0 } from './instance' ; import version from './version' ; import { getConfig , getLoginUrl , ConfigParameters } from './config' ; let instance ; function getInstance ( ) { if ( instance ) { return instance ; } instance = initAuth0 ( ) ; return instance ; } export const initAuth0 = ( params ) => { const { baseConfig , nextConfig } = getConfig ( params ) ; const getClient = clientFactory ( baseConfig , { name : 'nextjs-auth0' , version } ) ; const transientStore = new TransientStore ( baseConfig ) ; const cookieStore = new CookieStore ( baseConfig ) ; const sessionCache = new SessionCache ( baseConfig , cookieStore ) ; const baseHandleLogin = baseLoginHandler ( baseConfig , getClient , transientStore ) ; const baseHandleLogout = baseLogoutHandler ( baseConfig , getClient , sessionCache ) ; const baseHandleCallback = baseCallbackHandler ( baseConfig , getClient , sessionCache , transientStore ) ; const getSession = sessionFactory ( sessionCache ) ; const getAccessToken = accessTokenFactory ( nextConfig , getClient , sessionCache ) ; const withApiAuthRequired = withApiAuthRequiredFactory ( sessionCache ) ; const withPageAuthRequired = withPageAuthRequiredFactory ( nextConfig . routes . login , getSession ) ; const handleLogin = loginHandler ( baseHandleLogin , nextConfig , baseConfig ) ; const handleLogout = logoutHandler ( baseHandleLogout ) ; const handleCallback = callbackHandler ( baseHandleCallback , nextConfig ) ; const handleProfile = profileHandler ( getClient , getAccessToken , sessionCache ) ; const handleAuth = handlerFactory ( { handleLogin , handleLogout , handleCallback , handleProfile } ) ; return { getSession , getAccessToken , withApiAuthRequired , withPageAuthRequired , handleLogin , handleLogout , handleCallback , handleProfile , handleAuth } ; } ; export const getSession = ( ... args ) => getInstance ( ) . getSession ( ... args ) ; export const getAccessToken = ( ... args ) => getInstance ( ) . getAccessToken ( ... args ) ; export const withApiAuthRequired = ( ... args ) => getInstance ( ) . withApiAuthRequired ( ... args ) ; export const withPageAuthRequired = withPageAuthRequiredFactory ( getLoginUrl ( ) , getSession ) ; export const handleLogin = ( ... args ) => getInstance ( ) . handleLogin ( ... args ) ; export const handleLogout = ( ... args ) => getInstance ( ) . handleLogout ( ... args ) ; export const handleCallback = ( ... args ) => getInstance ( ) . handleCallback ( ... args ) ; export const handleProfile = ( ... args ) => getInstance ( ) . handleProfile ( ... args ) ; export const handleAuth = ( ... args ) => getInstance ( ) . handleAuth ( ... args ) ; export { UserProvider , UserProviderProps , UserProfile , UserContext , useUser , WithPageAuthRequiredProps } from './frontend' ; export { AccessTokenError , HandlerError } from './utils/errors' ; export { ConfigParameters , HandleAuth , HandleLogin , HandleProfile , HandleLogout , HandleCallback , ProfileOptions , Handlers , GetServerSidePropsResultWithSession , WithPageAuthRequiredOptions , PageRoute , WithApiAuthRequired , WithPageAuthRequired , SessionCache , GetSession , GetAccessToken , Session , Claims , AccessTokenRequest , GetAccessTokenResult , CallbackOptions , AfterCallback , AfterRefetch , LoginOptions , LogoutOptions , GetLoginState } ;