Replies: 1 comment 2 replies
-
Hello @V01D-NULL. I am trying to do something very similar. Would you be so kind and share the work you have done with the manual fetch requests as a reference point? Thank you! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
signIn()
functionality on a RSC or API routeNon-Goals
No response
Background
This was something that I came across at work.
We have multiple products & allow cross login (an account used to sign-up product A can be used to sign into product B & C and vice versa).
So, a sign-up form to create this generic email+password account (note: it is separate from next-auth, it is just a simple user.create() in a database) would exist on the company website, and after successful account creation the user is redirected to the product using next-auth.
The URL we redirected to was a RSC, so that we could run some server side logic right off the bat.
Now we have a valid account & credentials, but no clear way to actually authenticate the session from the server.
First idea that came to mind was convert the RSC into a client component and move all the logic to an API route. Then, we can call
signIn()
on component mount.That adds more complexity than necessary so I did some more digging.
What I ended up doing was writing fetch requests to manually hit the endpoint.
The alternative was to simply redirect to the sign-in route, but that is just poor UX since they're prompted to do it twice (once on the website, now for the product) and it can lead to annoying issues such as two accounts because the user made a typo after we redirected them to the sign-in page powered by next-auth.
Proposal
Pretty straight forward, take the client side
signIn
function and allow for this functionality on the server:I would be willing to create a PR for this since it's really just fetch requests, shouldn't take too long.
Just curious to see what the community/maintainers think, just looking through the documentation and discussions online I have not found any recommended solutions.
Last but not least.. this will only work with the credentials provider as far as I'm aware. There's just no way to truly automate oauth, but that should not be necessary anyways.
Beta Was this translation helpful? Give feedback.
All reactions