Register/singUP function with Custom backend in next auth v5?
Answered
rand posted this in #help-forum
randOP
Hello, i make an register api route in my django backend and can make new user, and got an access, refresh token, and what do i have to do?
next auth only supports signin? if so, do i need to call the sign in function after register?
what do you think folks?? thanks for your help and advice!!
next auth only supports signin? if so, do i need to call the sign in function after register?
what do you think folks?? thanks for your help and advice!!
Answered by B33fb0n3
Normally the register function just sign up a user. So it creates the user inside the database for example. However: it does not sign in the user. For that you can use the „signIn“ function from next-auth. That will send the login credentials trough your app and it will land inside your „CredentialsProvider“ (see next-auth docs). Inside your credentials provider you can then authorize your user so he is officially signed in
15 Replies
@rand Hello, i make an register api route in my django backend and can make new user, and got an access, refresh token, and what do i have to do?
next auth only supports **signin**? if so, do i need to call the sign in function after register?
what do you think folks?? thanks for your help and advice!!
Yes, you need to create your own register page and own register functions. After that you can use your database and own backend inside the credentials provider
randOP
@B33fb0n3
Thanks for your help,
And could you plz describe what does
After that you can use your database and own backend inside the credentials provider mean?i am able to get all of user data and access and refresh token stuff after register, and so how can i call the callback functions like as login?
to save those tokens and user data to the session?
Here is the register action for get the data:
"use server";
import api from "./api";
export const registerAction = async (values: any) => {
try {
const res = await api.post("/api/auth/register/", {
username: values.name,
email: values.email,
password: values.password,
});
console.log("DDDDDDDDDDDDDD");
console.log(res.data);
} catch (error) {
console.log(error);
}
};and after this, how to do callback jwt and session like the signin?
@rand And could you plz describe what does `After that you can use your database and own backend inside the credentials provider` mean?
Normally the register function just sign up a user. So it creates the user inside the database for example. However: it does not sign in the user. For that you can use the „signIn“ function from next-auth. That will send the login credentials trough your app and it will land inside your „CredentialsProvider“ (see next-auth docs). Inside your credentials provider you can then authorize your user so he is officially signed in
Answer
randOP
well, okay, so I dont need to send all token stuffs when register,
@B33fb0n3 Normally the register function just sign up a user. So it creates the user inside the database for example. However: it does not sign in the user. For that you can use the „signIn“ function from next-auth. That will send the login credentials trough your app and it will land inside your „CredentialsProvider“ (see next-auth docs). Inside your credentials provider you can then authorize your user so he is officially signed in
randOP
right?
@rand well, okay, so I dont need to send all token stuffs when register,
Yes, you setup everything, so the user will be able to sign in
@B33fb0n3 Yes, you setup everything, so the user will be able to sign in
randOP
Okay, thank you ! @B33fb0n3
happy to help