diff --git a/app/(auth)/Verification/page.tsx b/app/(auth)/Verification/page.tsx new file mode 100644 index 0000000000000000000000000000000000000000..5a9dc37cdb8fd86dcbe6b0f09fa1d84398689605 --- /dev/null +++ b/app/(auth)/Verification/page.tsx @@ -0,0 +1,25 @@ +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 diff --git a/app/api/passwordChange/route.ts b/app/api/passwordChange/route.ts new file mode 100644 index 0000000000000000000000000000000000000000..6fb59f931df937e30fbbcc8deebb24885f4a4f21 --- /dev/null +++ b/app/api/passwordChange/route.ts @@ -0,0 +1,52 @@ + +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 diff --git a/app/api/verification/[token]/route.ts b/app/api/verification/[token]/route.ts index 3e018e33601c01adf8fda9dc42ceb680d3163ab5..87895f0c16af8d554933958e70d9795e961c30e4 100644 --- a/app/api/verification/[token]/route.ts +++ b/app/api/verification/[token]/route.ts @@ -57,5 +57,6 @@ export async function GET( activationDate: new Date(), }, }) - redirect('/login') + + redirect('/Verification') } \ No newline at end of file diff --git a/app/api/verifyEmail/route.ts b/app/api/verifyEmail/route.ts index b333390ab1a87285d8d9bc040b4572bb111c65ff..2bb4cf4675b4942066ee5fbda57857cfb85c8347 100644 --- a/app/api/verifyEmail/route.ts +++ b/app/api/verifyEmail/route.ts @@ -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.`, }; diff --git a/components/user-auth-form.tsx b/components/user-auth-form.tsx index 854daa91798f6fe78d57cdc4f5bb0770aa6e54d5..a65b31f3adf30d33fd5f0752625a5f6776b19491 100644 --- a/components/user-auth-form.tsx +++ b/components/user-auth-form.tsx @@ -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!🚀", }) } diff --git a/lib/validations/sendPasswordResetEmail.ts b/lib/validations/sendPasswordResetEmail.ts new file mode 100644 index 0000000000000000000000000000000000000000..6fa23519818de0765f0453ec0f179adaff247f71 --- /dev/null +++ b/lib/validations/sendPasswordResetEmail.ts @@ -0,0 +1,26 @@ + +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