Skip to content
Snippets Groups Projects
Commit 9536c40d authored by Caner's avatar Caner
Browse files

little fix

parent aafd0c7b
No related branches found
No related tags found
1 merge request!45Email verify
......@@ -11,12 +11,12 @@ export default async function handler(
}
// https://nodemailer.com/smtp/
const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gameunity.tgos@gmail.com",
port: 587,
auth: {
user: process.env.NODEMAIL_MAIL,
pass: process.env.NODEMAIL_PW,
},
secure: false, // Default value but showing for explicitness
});
const { subject, email, html } = req.body;
......
......@@ -36,34 +36,34 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
const router = useRouter();
const searchParams = useSearchParams()
async function sendVerificationEmail(email: string) {
try {
const res = await fetch('/api/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
subject: 'Email Verification',
text: 'Please verify your email address.',
}),
});
// async function sendVerificationEmail(email: string) {
// try {
// const res = await fetch('/api/email', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify({
// email,
// subject: 'Email Verification',
// html: '<h1>Please verify your email address.</h1>',
// }),
// });
const body = await res.json();
// const body = await res.json();
if (res.ok) {
alert(`${body.message} 🚀`);
}
// if (res.ok) {
// alert(`${body.message} 🚀`);
// }
if (res.status === 400) {
alert(`${body.message} 😢`);
}
} catch (err) {
console.log('Something went wrong: ', err);
}
// if (res.status === 400) {
// alert(`${body.message} 😢`);
// }
// } catch (err) {
// console.log('Something went wrong: ', err);
// }
}
// }
async function onSubmit(data: FormData) {
setIsLoading(true)
......@@ -89,10 +89,11 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
setIsLoading(false)
return toast({
variant: "destructive",
title: "Uh oh! Something went wrong.",
title: "THIS Uh oh! Something went wrong.",
description: "Your sign up request failed. Please try again.",
})
}
// await sendVerificationEmail(data.email!)
}
const signInResult = await signIn("credentials", {
......@@ -124,7 +125,6 @@ export function UserAuthForm({ type, className, ...props }: UserAuthFormProps) {
action: <ToastAction altText="Try again">Try again</ToastAction>,
})
}
await sendVerificationEmail(data.email!)
router.push("/home")
......
import * as nodemailer from "nodemailer";
import { MailOptions } from "nodemailer/lib/json-transport";
export class Emailer {
private readonly transporter: nodemailer.Transporter;
constructor() {
this.transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.NODEMAIL_MAIL,
pass: process.env.NODEMAIL_PW,
},
});
}
public sendEmail(mailOptions: MailOptions) {
return this.transporter.sendMail(mailOptions);
}
public notifyAdminForNewUser(email: string, username: string) {
this.sendEmail(notifyAdminNewUserEmailTemplate(email, username));
}
public notifyUserForSignup(email: string, username: string) {
this.sendEmail(newUserEmailTemplate(email, username));
}
}
export const emailer = new Emailer();
export const newUserEmailTemplate = (email: string, username: string) => {
return {
from: process.env.GMAIL_USER,
to: email,
subject: `${username}, Welcome to the our website`,
text: "Welcome to the our website",
html: `
<h1>Welcome to our website!</h1>
<p>We're glad you've decided to join us. We hope you find everything you're looking for here and enjoy using our site.</p>
<p>If you have any questions or need any help, please don't hesitate to contact us. Thank you for signing up!</p>
`,
} as MailOptions;
};
export const notifyAdminNewUserEmailTemplate = (
email: string,
username: string
) => {
return {
from: process.env.GMAIL_USER,
to: process.env.GMAIL_USER,
subject: `New User: ${username} - email: ${email}`,
text: `New User: ${username} - email: ${email}`,
html: `
<h1>New User: ${username}</h1>
<p>email: ${email}</p>
`,
} as MailOptions;
};
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