Integrate Auth0 with Angular SSR

Hello,

I have an application on Angular 11.
After implementing SSR, I got the error “For security reasons, window.crypto is required to run `auth0-spa-js” and I know it is because of SSR not allowing “window”.

Question is, how can avoid this problem by auth0 side.

Thank you in advance.

Elias.

2 Likes

Hi @eliasruizdiaz,

Thanks for joining the Community!

I will have to do some research on this and I will let you know what I find.

It looks like there has been a github issue which may be helpful as well:

1 Like

Thank you so much for your answer and willingness. I still not finding any good solution, did you find something? :smiley:

1 Like

Hi @eliasruizdiaz,

Sorry for the delay in responding! Looking at the source code for auth0-spa-js, window.crypto is validated only if window is defined: auth0-spa-js/Auth0Client.ts at master · auth0/auth0-spa-js · GitHub

In your application, is window available even though it is SSR?

If an error is thrown in this case, I’d recommend opening up an issue in the repo directly so that the maintainers may assist. Issues · auth0/auth0-spa-js · GitHub

+1 to this issue! I’m using @auth0/auth0-angular specifically so the workaround they suggest in the existing Github issue (On Netlify: `window.crypto` is required to run `auth0-spa-js` · Issue #522 · auth0/auth0-spa-js · GitHub) isn’t an easy option.

2 Likes

Hi @noragrossman,

Thanks for the reply! It’d be best to open an issue on the repo for this so that the maintainers can assist directly: Issues · auth0/auth0-spa-js · GitHub

@stephanie.chamblee thank you for you update !!

“window” isn’t available in Angular SSR, indeed we need some npm package compatible with Angular SSR (Angular Universal). As @noragrossman has said, isn’t a easy option…

By other hand, we can open an issue on that repo, just asking here if someone has found a workaround by now.

Thank you so much!

1 Like

Thanks @eliasruizdiaz! Yes, I’d suggest opening an issue in this case.