Reputation:
I'm trying to create a sign up page and currently integrate signup with google with nextauth.
I have been able to integrate signIn with nextAuth and able to sign in (However not able to create an actual user on the database...)
with:
import { getProviders, signIn as SignIntoProvider } from 'next-auth/react';
where signIn exists in next-auth/react-- when searching for signUp or newUser, it doesn't exist... is there any other place where I should be looking for?
As there is supposed to be signIn, signUp, and signOut. I'm not able to access signUp for some reason...
Upvotes: 2
Views: 3482
Reputation: 71
But you can create your own route in the API. something like /api/auth/signup.js and then handle the signup process inside that.
async function handler(req, res) {
if (req.method !== "POST") {
return;
}
const data = req.body;
const { email, password } = data;
if (
!email ||
!email.includes("@") ||
!password ||
password.trim().length < 7
) {
res.status(422).json({
message:
"Invalid input - password should also be at least 7 characters long.",
});
return;
}
... YOUR SIGNUP LOGIC ...
}
export default handler;
Upvotes: 0
Reputation: 136
The signUp function doesn't exists, but you can use NextAuth callbacks to save the user on your database.
When a user sign in, query the db to check if it already exists, and if it doesn't, you create it.
Here is the documentation reference of how to use the signIn callback:
NextAuth Callbacks documentation
Upvotes: 2