-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
54 lines (52 loc) · 1.62 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type { GetServerSidePropsContext, NextApiRequest, NextApiResponse } from "next";
import type { NextAuthOptions } from "next-auth";
import { getServerSession } from "next-auth";
import { env } from "./lib/env";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import db from "@/db";
import * as schema from "@/db/schema";
export const authOptions: NextAuthOptions = {
adapter: DrizzleAdapter(db, {
usersTable: schema.users,
accountsTable: schema.accounts,
sessionsTable: schema.sessions,
verificationTokensTable: schema.verificationTokens,
}),
providers: [
{
id: "gumroad",
name: "Gumroad",
type: "oauth",
version: "2.0",
token: "https://api.gumroad.com/oauth/token",
authorization: {
url: "https://gumroad.com/oauth/authorize",
params: {
scope: "view_profile edit_products",
},
},
userinfo: "https://api.gumroad.com/v2/user",
clientId: env.GUMROAD_OAUTH_CLIENT_ID,
clientSecret: env.GUMROAD_OAUTH_CLIENT_SECRET,
profile: async (profileData: { user: { id: string; name: string; email: string } }) => {
return {
id: profileData.user.id,
name: profileData.user.name,
email: profileData.user.email,
};
},
},
],
callbacks: {
session: async ({ session, user }) => {
session.user.id = user.id;
return session;
},
},
};
// Use it in server contexts
export function auth(
...args: [GetServerSidePropsContext["req"], GetServerSidePropsContext["res"]] | [NextApiRequest, NextApiResponse] | []
) {
return getServerSession(...args, authOptions);
}