Use case for cookie-authentication #3882
-
Question 💬Hi all, thank you for amazing library. First of all, I read a lot the documentation and I'm not finding what I'm looking for I have a glimpse of a solution but, not see a good fit of it. That's why I'm asking this question. The use-case is very simple. I need to implement a redirection authentication through a cookie. No credentials input, no external providers. The user clicks in another internal application, the redirection has cookies to another subdomain, (httpOnly, sameSite, Secure). I need to verify the code authenticity and retrieve user identification. Is this possible that this is not a use-case for this library? Thank you in advance. How to reproduce ☕️I came across a hacking solution using Credentials, and when the users lands in SignIn, post empty credentials after 500ms in setTimeout with the cookies. Then, in the Note aside: I could help for a PR if it is needed. But, don't think this is the case. Thanks! Contributing 🙌🏽Yes, I am willing to help answer this question in a PR |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So if I understand correctly, you have the app with NextAuth.js (A), and another one (B).
And you want to skip 4 and 5. It almost sounds like NextAuth.js has no place in this flow. You could create an API route that is similar to what our NextAuth.js manages (creates/updates/deletes) its own session, created for the exact same domain. What you could do instead is if B is also a Next.js app, you can configure the session cookie in a way that even if it's set by another subdomain, it's still available in app A. https://next-auth.js.org/configuration/options#cookies That way, when landing on app A after the redirect, the user would already be logged in. |
Beta Was this translation helpful? Give feedback.
So if I understand correctly, you have the app with NextAuth.js (A), and another one (B).
authorize
callback verifies the cookie and returns the user.And you want to skip 4 and 5.
It almost sounds like NextAuth.js has no place in this flow. You could create an API route that is similar to what our
/api/auth/session
endpoint does, basically checking the cookie, if it's valid it returns it with an updated expiry, otherwise returns nothing.NextAuth.js manages (creates/updates/delet…