Skip to content

Commit

Permalink
chore: nodemailer and sonner
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshuverma-dev committed Oct 5, 2024
1 parent 768afc3 commit fff446e
Show file tree
Hide file tree
Showing 9 changed files with 871 additions and 113 deletions.
853 changes: 800 additions & 53 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
"drizzle-orm": "^0.33.0",
"next": "14.2.5",
"next-auth": "^5.0.0-beta.22",
"nodemailer": "^6.9.15",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.53.0",
"react-hot-toast": "^2.4.1",
"react-otp-input": "^3.1.1",
"resend": "^4.0.0",
"sonner": "^1.5.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/node": "^20",
"@types/nodemailer": "^6.4.16",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
Expand Down
19 changes: 6 additions & 13 deletions src/app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import { hash } from "bcryptjs";
import { NextRequest, NextResponse } from "next/server";
import { z } from "zod";

import { Resend } from 'resend';
import otpEmailTemplate from "@/lib/templates/otp-template";
import mailer from "@/lib/mailer";



const resendAPI = process.env.RESEND_API_KEY;
// `[email protected]` email is for development only
const senderEmail = process.env.SENDER_EMAIL || "[email protected]";

// `[email protected]` email is for development only
const resendEmail = process.env.RESENDL_EMAIL || "[email protected]";

const resend = new Resend(resendAPI);


export async function POST(req: NextRequest) {
Expand Down Expand Up @@ -69,17 +66,13 @@ export async function POST(req: NextRequest) {
});



const res = await resend.emails.send({
from: `Uttarakhand Culture <${resendEmail}>`,
await mailer.sendMail({
from: `Uttarakhand Culture <${senderEmail}>`,
to: [email],
subject: 'Verify you email with OTP',
html: otpEmailTemplate(name, otp),
});
})

if (res.error) {
console.log(res.error)
}



Expand Down
18 changes: 7 additions & 11 deletions src/app/api/auth/resend-otp/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import { otps } from "@/lib/schema";
import { NextRequest, NextResponse } from "next/server";
import { z } from "zod";

import { Resend } from 'resend';
import otpEmailTemplate from "@/lib/templates/otp-template";
import { auth } from "@/auth";
import mailer from "@/lib/mailer";



const resendAPI = process.env.RESEND_API_KEY;
// `[email protected]` email is for development only
const resendEmail = process.env.RESENDL_EMAIL || "[email protected]";
const resend = new Resend(resendAPI);
// `[email protected]` email is for development only
const senderEmail = process.env.SENDER_EMAIL || "[email protected]";


export async function POST(req: NextRequest) {
Expand Down Expand Up @@ -60,16 +58,14 @@ export async function POST(req: NextRequest) {



const res = await resend.emails.send({
from: `Uttarakhand Culture <${resendEmail}>`,

await mailer.sendMail({
from: `Uttarakhand Culture <${senderEmail}>`,
to: [userWithEmail.email!],
subject: 'Verify you email with OTP',
html: otpEmailTemplate(userWithEmail.name!, otp),
});
})

if (res.error) {
console.log(res.error)
}



Expand Down
2 changes: 1 addition & 1 deletion src/app/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import styles from "./page.module.css";
import toast from "react-hot-toast";
import { toast } from "sonner";
import { loginSchema, signupSchema } from "@/lib/zod";
import { signIn } from "next-auth/react";
import { useRouter } from "next/navigation";
Expand Down
2 changes: 1 addition & 1 deletion src/app/auth/verify/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import styles from "./page.module.css";
import React, { useEffect, useState } from "react";
import OtpInput from "react-otp-input";
import toast from "react-hot-toast";
import { toast } from "sonner";
import { useRouter } from "next/navigation";
const OtpPage: React.FC = () => {
const [otp, setOtp] = useState<string>("");
Expand Down
69 changes: 38 additions & 31 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import localFont from "next/font/local";
import Navbar from "@/components/ui/Navbar";
import Footer from "@/components/ui/Footer";
import { Toaster } from "react-hot-toast";
import { Toaster } from "sonner";
import { auth } from "@/auth";
import { redirect } from "next/navigation";
import { headers } from "next/headers";
Expand All @@ -16,35 +16,42 @@ const customFont = localFont({
});

export const metadata: Metadata = {
title: "Uttarakhand Culture - Explore Devbhoomi's Heritage, Traditions, and Natural Beauty",
description: "Explore the rich cultural heritage of Uttarakhand, Devbhoomi's vibrant festivals, traditions, folklore, and breathtaking landscapes. Join our mission to preserve and celebrate the heritage of Manaskhand and Kedarkhand for future generations.",
keywords: "Uttarakhand, culture, Devbhoomi, Uttarakhand culture, Pahadi culture, Uttarakhand heritage, Manaskhand, Kedarkhand, traditions, festivals, folk music, folk dances, digital preservation, Pahad, Pahadi, Pahadi traditions, Garhwali, Kumaoni, Himalayan culture, Uttarakhand tourism, cultural preservation, spiritual Uttarakhand, pilgrimage, Uttarakhand cuisine, Uttarakhand art, Uttarakhand history, Nanda Devi, Chhota Kailash, Ganga, Yamuna, Himalayan rivers, Uttarakhand flora fauna, mountain culture",
openGraph: {
title: "Uttarakhand Culture - Explore Devbhoomi's Heritage, Traditions, and Natural Beauty",
description: "Discover Uttarakhand's cultural heritage, festivals, traditions, folklore, and stunning natural beauty. Join our mission to digitally preserve and celebrate the vibrant legacy of Devbhoomi for future generations.",
url: "https://uttarakhand-culture.vercel.app",
siteName: "Uttarakhand Culture",
images: [
{
url: "/SEOIMAGE.webp",
alt: "Cultural Heritage of Uttarakhand - Traditions, Festivals, and Natural Beauty",
},
],
locale: "en_US",
type: "website",
},
twitter:{
card: "summary_large_image",
site: "https://uttarakhand-culture.vercel.app",
creator: "@UttarakhandCulture",
title: "Uttarakhand Culture - Explore Devbhoomi's Heritage, Traditions, and Natural Beauty",
description:"Discover Uttarakhand's cultural legacy, rich history, festivals, and natural beauty. Help us preserve the traditions of Devbhoomi for future generations.",
images: "/SEOIMAGE.webp"
},
robots: {
index: true,
follow: true,
},
title:
"Uttarakhand Culture - Explore Devbhoomi's Heritage, Traditions, and Natural Beauty",
description:
"Explore the rich cultural heritage of Uttarakhand, Devbhoomi's vibrant festivals, traditions, folklore, and breathtaking landscapes. Join our mission to preserve and celebrate the heritage of Manaskhand and Kedarkhand for future generations.",
keywords:
"Uttarakhand, culture, Devbhoomi, Uttarakhand culture, Pahadi culture, Uttarakhand heritage, Manaskhand, Kedarkhand, traditions, festivals, folk music, folk dances, digital preservation, Pahad, Pahadi, Pahadi traditions, Garhwali, Kumaoni, Himalayan culture, Uttarakhand tourism, cultural preservation, spiritual Uttarakhand, pilgrimage, Uttarakhand cuisine, Uttarakhand art, Uttarakhand history, Nanda Devi, Chhota Kailash, Ganga, Yamuna, Himalayan rivers, Uttarakhand flora fauna, mountain culture",
openGraph: {
title:
"Uttarakhand Culture - Explore Devbhoomi's Heritage, Traditions, and Natural Beauty",
description:
"Discover Uttarakhand's cultural heritage, festivals, traditions, folklore, and stunning natural beauty. Join our mission to digitally preserve and celebrate the vibrant legacy of Devbhoomi for future generations.",
url: "https://uttarakhand-culture.vercel.app",
siteName: "Uttarakhand Culture",
images: [
{
url: "/SEOIMAGE.webp",
alt: "Cultural Heritage of Uttarakhand - Traditions, Festivals, and Natural Beauty",
},
],
locale: "en_US",
type: "website",
},
twitter: {
card: "summary_large_image",
site: "https://uttarakhand-culture.vercel.app",
creator: "@UttarakhandCulture",
title:
"Uttarakhand Culture - Explore Devbhoomi's Heritage, Traditions, and Natural Beauty",
description:
"Discover Uttarakhand's cultural legacy, rich history, festivals, and natural beauty. Help us preserve the traditions of Devbhoomi for future generations.",
images: "/SEOIMAGE.webp",
},
robots: {
index: true,
follow: true,
},
};

export default async function RootLayout({
Expand All @@ -71,7 +78,7 @@ export default async function RootLayout({
<Navbar />
{children}
{/*<SpeedInsights />*/}
<Toaster />
<Toaster position="top-right" />
<Footer />
</main>
</body>
Expand Down
15 changes: 15 additions & 0 deletions src/lib/mailer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import nodemailer from 'nodemailer';



const mailer = nodemailer.createTransport({
host: process.env.MAIL_SERVER_HOST as string,
port: 587,
secure: false, // Use `true` for port 465, `false` for all other ports
auth: {
user: process.env.MAIL_SERVER_USER,
pass: process.env.MAIL_SERVER_PASS,
}
});

export default mailer;
1 change: 0 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default auth((req) => {
headers.set("x-current-path", req.nextUrl.pathname);


console.log(req.auth)

if (isApiAuthRoute) {
return;
Expand Down

0 comments on commit fff446e

Please sign in to comment.