-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.config.ts
46 lines (45 loc) · 1.24 KB
/
auth.config.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
39
40
41
42
43
44
45
46
import Google from '@auth/core/providers/google';
import { DrizzleAdapter } from '@auth/drizzle-adapter';
import { db } from '@lib/db';
import { accounts, userTable } from '@lib/db/schema';
import { defineConfig } from 'auth-astro';
import { eq } from 'drizzle-orm';
export default defineConfig({
providers: [
Google({
clientId: import.meta.env.AUTH_GOOGLE_ID,
clientSecret: import.meta.env.AUTH_GOOGLE_SECRET,
}),
],
callbacks: {
async jwt({ token }) {
if (!token.sub) return token;
const user = await db.query.userTable.findFirst({
where: eq(userTable.id, token.sub),
});
if (!user) return token;
token = {
...token,
email: user.email,
name: user.name,
};
return token;
},
async session({ session, token }) {
if (!token.sub) return session;
if (token.sub && session.user) {
session.user.id = token.sub;
}
if (session.user) {
session.user.email = token.email as string;
session.user.name = token.name as string;
}
return session;
},
},
adapter: DrizzleAdapter(db, {
usersTable: userTable,
accountsTable: accounts,
}),
session: { strategy: 'jwt', maxAge: 365 * 24 * 60 * 60 },
});