-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
35 lines (31 loc) · 874 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
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { db } from "./db";
import { HTTPException } from "hono/http-exception";
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: DrizzleAdapter(db),
providers: [
Google({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
}),
],
callbacks: {
session: async ({ session, user }) => {
if (session?.user) {
session.user.id = user.id;
}
return session;
},
},
events: {},
});
export async function authenticateUser() {
const session = await auth();
if (!session || !session.user || !session.user.id) {
throw new HTTPException(401, { message: "Unauthorized" });
}
const userId = session.user.id;
return userId;
}