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

Ccreating a session from backend code #6087

Closed
ChayaninSuatap opened this issue Dec 16, 2022 · 2 comments
Closed

Ccreating a session from backend code #6087

ChayaninSuatap opened this issue Dec 16, 2022 · 2 comments
Labels
question Ask how to do something or how something works

Comments

@ChayaninSuatap
Copy link

ChayaninSuatap commented Dec 16, 2022

Question 💬

My scenario is that I used an external OAuth service. After the user sign in successfully, the OAuth will redirect to my API route with user information (NEXT.js API route) Then I want to create a session using the information returned from OAuth.

So, is there a way to create a session directly from backend code without signing in from the frontend? (The OAuth service I used has their own sign in page).
I have search in the document and found that I may have to setup a custom provider. But, to be honest, it is quite scary for me to do all the configs 😢. So if there's a way to get around that, it will be good.

I also tried to use the signIn function which imported from "next-auth/react" and, obviously, it is not working. Because this signIn is intended to be used only on the frontend (It involves the window object on browser)

@ChayaninSuatap ChayaninSuatap added the question Ask how to do something or how something works label Dec 16, 2022
@Nisthar
Copy link

Nisthar commented Dec 16, 2022

@ChayaninSuatap I think your question is similar to what i asked here #6086
A lot of backends handle the oauth themselves. The problem is handling the refresh tokens and access tokens in both client and server.

@balazsorban44
Copy link
Member

If you don't need user interaction, you are likely looking for a machine to machine or client credentials flow and you don't really need next-auth

https://oauth.net/2/grant-types/client-credentials/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

3 participants