-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
46 lines (44 loc) · 1.25 KB
/
auth.ts
File metadata and controls
46 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import NextAuth from "next-auth";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import Resend from "next-auth/providers/resend";
import EmailProvider from "next-auth/providers/email";
import { db } from "@/schema/db";
let provider = [];
const development = process.env.NODE_ENV === "development";
if (development) {
provider = [
/**
* EmailProvider is a custom provider that simulates sending a magic link, but instead
* logs the link to the console. This is used for development environments to make auth
* easier to work with.
*/
EmailProvider({
from: process.env.MAILER_ADDRESS,
server: "someServer",
sendVerificationRequest: async ({ url }) => {
console.log("Simulating Email Send");
console.log("✨✨ Email Auth Magic Link ✨✨\n\n", url, "\n\n");
},
}),
];
} else {
/**
* List any actual providers being used here.
*/
provider = [
Resend({
from: process.env.MAILER_ADDRESS,
}),
];
}
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: DrizzleAdapter(db),
providers: provider,
trustHost: true,
events: {
async createUser(message) {
const { user } = message;
console.log("User Created:", user);
},
},
});