Skip to content

Commit

Permalink
refactor: set resend as custom email provider and remove nodemailer
Browse files Browse the repository at this point in the history
  • Loading branch information
moinulmoin committed Jul 29, 2023
1 parent 81afea3 commit e03adfa
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
]
},
"ignorePatterns": [
"next.config.js"
"*.config.js"
]
}
2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"config": "tailwind.config.js",
"css": "src/app/globals.css",
"baseColor": "slate",
"cssVariables": true
Expand Down
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { withContentlayer } = require("next-contentlayer");
const withPWA = require("@ducanh2912/next-pwa").default({
dest: "public",
disable: process.env.NODE_ENV !== "production",
});

/** @type {import('next').NextConfig} */
Expand All @@ -9,6 +10,9 @@ const nextConfig = {
swcMinify: true,
experimental: {
serverActions: true,
serverComponentsExternalPackages: [
"@prisma/client",
],
},
};

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"next-auth": "^4.22.1",
"next-contentlayer": "^0.3.3",
"next-themes": "^0.2.1",
"nodemailer": "^6.9.3",
"postcss": "8.4.24",
"prisma": "^5.0.0",
"react": "18.2.0",
Expand Down
15 changes: 3 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/layout/auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function AuthForm() {
saCheckEmailExists(data.email.toLowerCase())
.then(async () => {
try {
const res = await signIn("email", {
const res = await signIn("resend", {
email: data.email.toLowerCase(),
redirect: false,
});
Expand Down
38 changes: 22 additions & 16 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { type NextAuthOptions } from "next-auth";
import EmailProvider, {
type SendVerificationRequestParams,
} from "next-auth/providers/email";
import { type SendVerificationRequestParams } from "next-auth/providers/email";
import GithubProvider from "next-auth/providers/github";
import db from "~/lib/db";
import { sendMail } from "~/lib/resend";

const sendVerificationRequest = async ({
identifier,
identifier: email,
url,
}: SendVerificationRequestParams) => {
const user = await db.user.findFirst({
where: {
email: identifier,
email,
},
select: {
emailVerified: true,
name: true,
},
});

await sendMail({
toMail: identifier,
type: "verification",
data: {
name: user?.name as string,
url,
},
});
try {
await sendMail({
toMail: email,
type: "verification",
data: {
name: user?.name as string,
url,
},
});
} catch (error) {
throw new Error(JSON.stringify(error));
}
};

export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(db),
providers: [
EmailProvider({
{
id: "resend",
type: "email",
name: "Email Provider",
server: null,
options: {},
sendVerificationRequest,
}),
},
GithubProvider({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
Expand Down
File renamed without changes.

1 comment on commit e03adfa

@vercel
Copy link

@vercel vercel bot commented on e03adfa Jul 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.