-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.config.js
More file actions
44 lines (38 loc) · 1.38 KB
/
auth.config.js
File metadata and controls
44 lines (38 loc) · 1.38 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
import GitHub from "@auth/core/providers/github";
import { defineConfig } from "auth-astro";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
if (!import.meta.env.SUPABASE_URL) {
throw new Error("Missing SUPABASE_URL");
}
//
const client = postgres(import.meta.env.SUPABASE_URL);
const db = drizzle(client);
export default defineConfig({
providers: [
GitHub({
authorization: {
url: "https://github.com/login/oauth/authorize",
params: { scope: "read:user user:email read:org" },
},
clientId: import.meta.env.GITHUB_CLIENT_ID,
clientSecret: import.meta.env.GITHUB_CLIENT_SECRET,
async profile(profile, tokens) {
const org = await fetch(
`https://api.github.com/orgs/relagit/memberships/${profile.login}`,
{
headers: {
Authorization: `Bearer ${tokens.access_token}`,
},
},
).then(async (res) => await res.json());
return {
id: profile.id.toString(),
name: profile.name ?? profile.login,
image: profile.avatar_url,
email: org.role ?? "user",
};
},
}),
],
});