Skip to content
Snippets Groups Projects
Commit 64f2341a authored by Caner's avatar Caner
Browse files

Email Verification fixes + Password reset start

parent c7b7412d
No related branches found
No related tags found
1 merge request!45Email verify
Pipeline #39676 passed
import Link from "next/link"
import { GameUnityLogo } from "@/components/logo"
import { buttonVariants } from "@/components/ui/button"
import { cn } from "@/lib/utils"
export default function EmailVerification() {
return (
<div className="container flex max-w-[64rem] flex-col items-center gap-4 text-center">
<div className="flex items-center">
<Link href="/home" className={cn("rounded-full p-3 hover:bg-accent")}>
<GameUnityLogo className="h-10 w-10" />
</Link>
</div>
<p className="max-w-[42rem] leading-normal sm:text-xl sm:leading-8">
Your Email has been Verified and your Account was Activated <br /> You can now login
</p>
<div className="align-middle">
<Link href="/login" className={cn(buttonVariants({ size: "lg" }), "mr-6")}>
Login
</Link>
</div>
</div>
)
}
\ No newline at end of file
import nodemailer from "nodemailer";
import { NextResponse } from "next/server";
import { db } from "@/lib/db";
import { randomUUID } from "crypto";
import getURL from "@/lib/utils";
export async function POST(req: Request) {
const { email} = await req.json();
const transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
user: process.env.NODEMAIL_MAIL,
pass: process.env.NODEMAIL_PW,
},
});
const user = await db.user.findFirst({
where: {
email: email
}
});
const token = await db.activationToken.create({
data: {
token: `${randomUUID()}${randomUUID()}`.replace(/-/g, ''),
userId: user?.id!
},
});
const mailData = {
from: process.env.NODEMAIL_MAIL,
to: email,
subject: ` 'Password Reset for your GameUnity account`,
html: `Hello ${user?.name} you requeste a password reset. \nPlease follow the Link: ${getURL(`/api/verification/${token.token}`)} to change your password.`,
};
let emailRes;
try {
emailRes = await transporter.sendMail(mailData);
console.log("Message sent", emailRes.messageId);
} catch (err) {
console.log(err);
console.error("Error email could not be send");
}
console.log(emailRes?.messageId)
return NextResponse.json({ success: true, messageId: emailRes?.messageId });
}
\ No newline at end of file
......@@ -57,5 +57,6 @@ export async function GET(
activationDate: new Date(),
},
})
redirect('/login')
redirect('/Verification')
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ export async function POST(req: Request) {
const mailData = {
from: process.env.NODEMAIL_MAIL,
to: email,
subject: ` 'Email Verification for your GameUnity Account'`,
subject: `Email Verification for your GameUnity Account`,
html: `Hello ${user?.name} Please follow the Link: ${getURL(`/api/verification/${token.token}`)} and verify your email address.`,
};
......
......@@ -94,7 +94,7 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
}
if (signInResult.error === "Email is not verified") {
return toast({
title: "Verify your account.",
title: "Please Verify your account.",
description: "We send you a email to verify your Account. Please check your Mailbox!🚀",
})
}
......
export async function sendPasswordResetEmail(email: string) {
try {
const res = await fetch('/api/passwordChange', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
}),
});
if (res.ok) {
alert(`PasswordChange Email was send 🚀`);
}
if (res.status === 400) {
alert(`Something went wrong! Password reset Email could not be send 😢`);
}
} catch (err) {
console.log('Something went wrong: ', err);
}
}
\ No newline at end of file
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