bug fixed
This commit is contained in:
parent
6544e3ecbb
commit
2264abd384
|
@ -1200,6 +1200,28 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
|
|||
if (trigger === "signIn" || trigger === "signUp")
|
||||
token.id = user?.id as number;
|
||||
|
||||
if (trigger === "signUp") {
|
||||
const checkIfUserExists = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: token.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (checkIfUserExists && !checkIfUserExists.username) {
|
||||
const autoGeneratedUsername =
|
||||
"user" + Math.round(Math.random() * 1000000000);
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: token.id,
|
||||
},
|
||||
data: {
|
||||
username: autoGeneratedUsername,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
},
|
||||
async session({ session, token }) {
|
||||
|
|
Ŝarĝante…
Reference in New Issue