Skip to content
Snippets Groups Projects
Commit 8237fc84 authored by Caner's avatar Caner
Browse files

VerificationEmail fix

parent a7d4584e
No related branches found
No related tags found
1 merge request!45Email verify
Pipeline #39308 passed
......@@ -45,7 +45,7 @@ export async function GET(
id: user.id,
},
data: {
emailVerified: true,
emailVerified: new Date(Date.now()),
},
})
......
......@@ -67,6 +67,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
description: "Your sign up request failed. Please try again.",
})
}
await sendVerificationEmail(data.email!)
}
const signInResult = await signIn("credentials", {
......@@ -91,6 +92,12 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
message: 'Sorry, but it seems like the password you entered is invalid. Please try again.'
});
}
if (signInResult.error === "Email is not verified") {
return toast({
title: "You have to verify your account to Login",
description: "We send you a email to verify your Account. Please check your Mailbox!🚀",
})
}
return toast({
variant: "destructive",
title: "Uh oh! Something went wrong.",
......@@ -101,13 +108,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
router.push("/home")
if (type === "signup") {
await sendVerificationEmail(data.email!)
return toast({
title: "Congratulations!",
description: "Your account has been created. You will be redirected shortly.",
})
} else {
if (type !== "signup") {
return toast({
title: "Login successful.",
description: "You will be redirected shortly.",
......
......@@ -7,6 +7,7 @@ import { Adapter } from "next-auth/adapters"
import CredentialsProvider from 'next-auth/providers/credentials'
import GitHubProvider from "next-auth/providers/github"
import { normalize } from "normalize-diacritics"
import { sendVerificationEmail } from "./validations/sendVerificationEmail"
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(db as any) as Adapter,
......@@ -51,6 +52,10 @@ export const authOptions: NextAuthOptions = {
user.password
)
if(!user.emailVerified){
throw new Error('Email is not verified')
}
if (!isPasswordValid) {
throw new Error('invalid password')
}
......
......@@ -13,9 +13,9 @@ export async function sendVerificationEmail(email: string) {
}),
});
if (res.ok) {
alert(`Verification Email was send 🚀,/n Please Verify your Account!`);
}
// if (res.ok) {
// alert(`Verification Email was send 🚀,/n Please Verify your Account!`);
// }
if (res.status === 400) {
alert(`Something went wrong! Verification Email could not be send 😢`);
......
......@@ -58,7 +58,7 @@ model User {
name String
username String? @unique
email String? @unique
emailVerified Boolean @default(false)
emailVerified DateTime? @map("email_verified")
password String?
image String?
banner String?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment