forked from dcramer/gamegame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
38 lines (36 loc) · 973 Bytes
/
auth.ts
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
import NextAuth from "next-auth";
import Resend from "next-auth/providers/resend";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "./lib/db";
import {
accounts,
sessions,
users,
verificationTokens,
} from "./lib/db/schema/auth";
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: DrizzleAdapter(db, {
// i dont fucking have a clue what i'm doing
usersTable: users as any,
accountsTable: accounts as any,
sessionsTable: sessions as any,
verificationTokensTable: verificationTokens as any,
}),
providers: [
Resend({
from: "[email protected]",
}),
],
callbacks: {
authorized: async ({ request, auth }) => {
if (
!auth &&
request.nextUrl.pathname !== "/login" &&
request.nextUrl.pathname !== "/"
) {
const newUrl = new URL("/login", request.nextUrl.origin);
return Response.redirect(newUrl);
}
},
},
});