Replies: 2 comments 3 replies
-
Yes, you can use the ID token from the cookie if you want (or the user's auth info directly), though there's not a helper in this package for doing so. You shouldn't have to handle refreshing the token in this case because the auth cookies are automatically updated when the Firebase JS SDK updates an ID token. However, you should still validate any ID token you're using. One possible corner case bug: when using this package, it's possible for a user to be authed but not have cookies set. This would happen when the user is logged in to Firebase but (for example) cleared cookies prior to a page load. Before the call to login, any other API calls would be missing auth cookies. My two cents: unless you have a compelling reason for using cookies, I'd recommend using an auth token in a header. It avoids some potential CSRF-related security holes, would make your API endpoints easier to use from other non-web apps, and is more in line with how Firebase services work. |
Beta Was this translation helpful? Give feedback.
-
Hi @alextaymx , So I have created an API Middleware (withAuthUserTokenAPI.ts):
The in the api route you wrap your 'handler' with this Middleware; eg:
Lastly to call your API, you need to provide a
|
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
Im currently investigating if I would use in an upcoming project firebase with NextJS. Is there a simple way to protect an API route? I've seen that you pass the Authentification token to fetch the API example but would it not be simpler to check the cookie on server side to validate if the API is protected? I was using for an Auth0 project
nextjs-auth0
(https://github.com/auth0/nextjs-auth0#api-reference) which did a similar job just instead of Firebase it was Auth0Describe the solution you'd like and how you'd implement it
Similar to protect SSR routes protecting API routes
Is this a breaking change?
I don't think so
Describe alternatives you've considered
Currently pass the token from client to server via headers but I think there could be a simpler approach
Beta Was this translation helpful? Give feedback.
All reactions