Skip to content

ERROR ReferenceError: window is not defined - Support For SSR / prerender #1408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ev45ive opened this issue Apr 24, 2024 · 2 comments
Open

Comments

@ev45ive
Copy link

ev45ive commented Apr 24, 2024

Angular 17 enabled SSR and prerender by default and this library uses window, not globalThis and doesn't detect if in SSR/Edge
so programmer has to those checks and wrap things with isPlatformBrowser() checks.

I am not sure if whole server side flow is planed in scope of this library, but making tryLogin / initLoginFlow a NO-OP in SSR? maybe?

@ev45ive
Copy link
Author

ev45ive commented Jun 12, 2024

Temporary Fix:

 oauth = inject(OAuthService)
 pid =inject(PLATFORM_ID)

  ngOnInit(): void {
    if(isPlatformBrowser(this.pid))
    this.oauth.tryLogin()
  }
export const authConfig: AuthConfig = {

  // URL of the SPA to redirect the user to after loginemv
  redirectUri: globalThis.location?.origin + '/callback',
 

@mmoya26
Copy link

mmoya26 commented Aug 7, 2024

@ev45ive Hey just came across this issue, I'm getting console errors saying the window is not defined whenever I do ng serve. is there a chance you can elaborate on this?

test

I tested the whole login flow and it is working. I'm looking at your temporary fix and I'm not sure where I'm supposed to place the first snippet of code you posted. I already adjusted the authConfig to have it look like yours. Again, I'm just not sure where in my code I need to place the first part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants