-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathauth.ts
More file actions
70 lines (67 loc) · 1.96 KB
/
auth.ts
File metadata and controls
70 lines (67 loc) · 1.96 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { NextAuthOptions } from "next-auth";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import GoogleProvider, { GoogleProfile } from "next-auth/providers/google";
import GithubProvider, { GithubProfile } from "next-auth/providers/github";
import { env } from "process";
import { accounts, sessions, users, verificationTokens } from "./db/schemas/users";
import { databaseDrizzle } from "./db";
const dcupEnv = env.DCUP_ENV
export const authOptions: NextAuthOptions = {
secret: env.NEXTAUTH_SECRET,
session: { strategy: "jwt" },
pages: {
signIn: "/login",
error: "/login",
},
adapter: DrizzleAdapter(databaseDrizzle, {
usersTable: users,
accountsTable: accounts,
sessionsTable: sessions,
verificationTokensTable: verificationTokens,
}),
callbacks: {
session: async ({ session, token }) => {
if (session) {
session.user.id = token.id as string;
session.user.name = token.name as string;
session.user.email = token.email as string;
session.user.image = token.picture as string
}
return session;
},
jwt: async ({ user, token }) => {
if (user) {
token.id = user.id;
}
return token;
},
},
providers: [
GoogleProvider({
clientId: env.NEXT_PUBLIC_GOOGLE_CLIENT_ID!,
clientSecret: env.GOOGLE_CLIENT_SECRET!,
profile(profile: GoogleProfile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
plan: dcupEnv === 'CLOUD' ? 'FREE' : 'OS'
};
},
}),
GithubProvider({
clientId: env.AUTH_GITHUB_ID!,
clientSecret: env.AUTH_GITHUB_SECRET!,
profile(profile: GithubProfile) {
return {
id: profile.id.toString(),
name: profile.name,
image: profile.avatar_url,
email: profile.email,
plan: dcupEnv === 'CLOUD' ? 'FREE' : 'OS'
};
},
}),
]
}