diff --git a/app/api/email/route.ts b/app/api/email/route.ts index 8ab1a1a3d57066e4053b74ea59ae54c06a00496d..d4c260b092075c3ad842b6a6bbc7238af03dba88 100644 --- a/app/api/email/route.ts +++ b/app/api/email/route.ts @@ -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; diff --git a/components/user-auth-form.tsx b/components/user-auth-form.tsx index dd9ce46f7bfe9ad1fd92208700e98e2e6a05bb81..d0c75d1899b9d757c86a771ed18b58f5f75a3860 100644 --- a/components/user-auth-form.tsx +++ b/components/user-auth-form.tsx @@ -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") diff --git a/lib/config/nodemailer.ts b/lib/config/nodemailer.ts deleted file mode 100644 index 7ec015fdbcdae7aaa7f3965799436c4bdea10126..0000000000000000000000000000000000000000 --- a/lib/config/nodemailer.ts +++ /dev/null @@ -1,62 +0,0 @@ - -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; -}; -