Open moklick opened 3 years ago
At the moment it is not possible to create an auth client within a nextjs app because the @8base/web-auth0-auth-client package uses the window object which is not defined in a ssr context.
@8base/web-auth0-auth-client
window
This is my code:
const origin = typeof window !== 'undefined' ? window.location.origin : ''; const authClient = Auth.createClient( { strategy: AUTH_STRATEGIES.WEB_8BASE, subscribable: true, }, { clientId: process.env.NEXT_PUBLIC_APP_AUTH_CLIENT_ID, domain: process.env.NEXT_PUBLIC_APP_AUTH_CLIENT_ID, redirectUri: `${origin}/auth/callback/path`, logoutRedirectUri: `${origin}/`, } );
It fails with an error that window is not defined.
The problem seems to be in web-auth0-auth-client/dist/WebAuth0AuthClient:
web-auth0-auth-client/dist/WebAuth0AuthClient
constructor(options, storage = window.localStorage, storageKey = 'auth')
when you check if the window exists, everything works fine.
@moklick We have not yet planned SSR support in the roadmap. Feel free to do any PR.
At the moment it is not possible to create an auth client within a nextjs app because the
@8base/web-auth0-auth-client
package uses thewindow
object which is not defined in a ssr context.This is my code:
It fails with an error that
window
is not defined.The problem seems to be in
web-auth0-auth-client/dist/WebAuth0AuthClient
:constructor(options, storage = window.localStorage, storageKey = 'auth')
when you check if the window exists, everything works fine.