gladly-team / next-firebase-auth

Simple Firebase authentication for all Next.js rendering strategies
https://nfa-example-git-v1x-gladly-team.vercel.app/
MIT License
1.35k stars 290 forks source link

Never throw when verifying ID token #366

Closed kmjennison closed 2 years ago

kmjennison commented 2 years ago

Is your feature request related to a problem? Please describe.

Currently, the SSR logic might throw if it's unable to verify the user's ID token. This is frustrating because it's not particularly easy for developers to catch errors in withAuthUserSSR/withAuthUserTokenSSR, and in most cases an unauthed user + optional error log is preferable to a 500 error. It would be better if the error didn't throw or was otherwise easily catchable.

361 handles more of the common Firebase errors but still throws unhandled errors.

Describe the solution you'd like and how you'd implement it

Don't throw when verifying the user's ID token server-side. Instead, return an unauthenticated user for any error, then call an optional onServerSideAuthError callback provided by the developer for the unexpected errors (ones we don't handle above).

Is this a breaking change?

Yes, a minor one, for developers that are expecting thrown errors from withAuthUserSSR or withAuthUserTokenSSR

Describe alternatives you've considered

None.