Skip to content
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

Example for /login and /logout api routes #34

Closed
gaschneidr opened this issue Mar 28, 2023 · 5 comments
Closed

Example for /login and /logout api routes #34

gaschneidr opened this issue Mar 28, 2023 · 5 comments

Comments

@gaschneidr
Copy link

Hi! I came across this package this week and it has been really helpful. Thank you.

I'd like to request that examples be added for the api login and logout routes. I've seen there are some helper methods for appending tokens in the api login method, and I managed to implement them myself. But others might struggle a bit more since none of the examples in the examples folder have those routes implemented. I also still didn't figure out how to implement the logout route.

Thanks for taking the time and providing the community this package!

@awinogrodzki
Copy link
Owner

Hey @gaschneidr!

I am not sure I understand the example you need here. When it comes to /api/login and /api/logout routes, those are handled in middleware.ts by authentication middleware. You can check example configuration here: https://github.com/awinogrodzki/next-firebase-auth-edge#authentication-middleware

There is also example on how to use those API routes inside React: https://github.com/awinogrodzki/next-firebase-auth-edge#example-authprovider

You just have to call them with fetch and pass firebase id token in Authorization headers :-)

Please let me know if I missed something

@awinogrodzki
Copy link
Owner

Hey! :-) I will close the issue now. If you feel like my answer did not resolve your query, please let me know and we'll reopen the issue!

@brianfryer
Copy link

@awinogrodzki I think I understand what @gaschneidr is saying.

In next-firebase-auth, there are examples of /api/login and /api/logout endpoints:

However, in next-firebase-auth-edge (this project), there are references to these endpoints but no examples of what these endpoints should look like.

What I think you're trying to say is that folks who use next-firebase-auth-edge don't need to create these endpoints in their NextJS project (i.e. ./app/login/route.js, ./app/logout/route.js).

For those of us who aren't familiar with middlware.js, it's not immediately obvious that these endpoints are automatically created/handled by placing middleware.js at the root of our NextJS project.

I'm glad this issue thread exists, as I was wondering the same thing: "What should my login/logout endpoints look like?" Now I understand that I need to ensure my middlware.js file is configured correctly 💪

🙏

@Vicidevs
Copy link

@brianfryer please does it mean that we don't need to create the two api endpoints i.e /api/login/route.ts and api/login/route.ts manually? Will the middleware create it under the hood? Because I clone the example, but when I tried to login after deployment it gave me error relating to api/login issue. Thanks

@awinogrodzki
Copy link
Owner

@Vicidevs, exactly. Those routes are handled by middleware under the hood. To be more exact, they are handled here: https://github.com/awinogrodzki/next-firebase-auth-edge/blob/main/src/next/middleware.ts#L33-L50

What error are you experiencing?

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

4 participants