Skip to content
Snippets Groups Projects
Commit 435a3656 authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

change verification casing

parent d47ca500
No related branches found
No related tags found
1 merge request!54Ui
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 { GameUnityLogo } from "@/components/logo"
import { buttonVariants } from "@/components/ui/button"
import { cn } from "@/lib/utils"
import Link from "next/link"
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
......@@ -2,60 +2,59 @@ import { db } from '@/lib/db'
import { redirect } from 'next/navigation'
import { NextRequest } from 'next/server'
export async function GET(
_request: NextRequest,
{
params,
}: {
params: { token: string }
}
_request: NextRequest,
{
params,
}: {
params: { token: string }
}
) {
const { token } = params
const { token } = params
const user = await db.user.findFirst({
where: {
ActivationToken: {
some: {
AND: [
{
activationDate: null,
},
{
createdAt: {
gt: new Date(Date.now() - 24 * 60 * 60 * 1000), // 24 hours ago
},
const user = await db.user.findFirst({
where: {
ActivationToken: {
some: {
AND: [
{
activationDate: null,
},
{
createdAt: {
gt: new Date(Date.now() - 24 * 60 * 60 * 1000), // 24 hours ago
},
},
{
token
},
],
},
},
{
token
},
],
},
},
},
})
})
if (!user) {
throw new Error('Token is invalid or expired')
}
if (!user) {
throw new Error('Token is invalid or expired')
}
const userUpdate = await db.user.update({
where: {
id: user.id,
},
data: {
emailVerified: new Date(Date.now()),
},
})
const userUpdate = await db.user.update({
where: {
id: user.id,
},
data: {
emailVerified: new Date(Date.now()),
},
})
const actiaction = await db.activationToken.update({
where: {
token,
},
data: {
activationDate: new Date(),
},
})
const actiaction = await db.activationToken.update({
where: {
token,
},
data: {
activationDate: new Date(),
},
})
redirect('/Verification')
redirect('/verify')
}
\ No newline at end of file
import { env } from "@/env.mjs"
import { db } from "@/lib/db"
import getURL from "@/lib/utils"
import { randomUUID } from "crypto"
import { NextResponse } from "next/server"
import nodemailer from "nodemailer"
export async function POST(req: Request) {
const { email } = await req.json()
const transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
user: env.NODEMAIL_MAIL,
pass: 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: env.NODEMAIL_MAIL,
to: email,
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.`,
}
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")
}
return NextResponse.json({ success: true, messageId: emailRes?.messageId })
}
\ 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";
import { env } from "@/env.mjs";
export async function POST(req: Request) {
const { email} = await req.json();
const transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
user: env.NODEMAIL_MAIL,
pass: 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: env.NODEMAIL_MAIL,
to: email,
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.`,
};
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
......@@ -7,7 +7,6 @@ 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,
......
export async function sendVerificationEmail(email: string) {
try {
const res = await fetch('/api/verifyEmail', {
const res = await fetch('/api/verify-email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
......@@ -11,16 +8,12 @@ export async function sendVerificationEmail(email: string) {
body: JSON.stringify({
email,
}),
});
// 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 😢`);
alert(`Something went wrong! Verification Email could not be send 😢`)
}
} catch (err) {
console.log('Something went wrong: ', 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