-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
64 lines (62 loc) · 1.75 KB
/
Copy pathauth.ts
File metadata and controls
64 lines (62 loc) · 1.75 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
import NextAuth from "next-auth"
import Discord from "next-auth/providers/discord";
import Slack from "next-auth/providers/slack";
import GitHub from "next-auth/providers/github";
export const { handlers, signIn, signOut, auth } = NextAuth({
theme: {
logo: "https://raw.githubusercontent.com/aelithron/universal-status/refs/heads/main/app/favicon.ico",
},
providers: providers(),
callbacks: {
authorized: async ({ request, auth }) => {
if (request.nextUrl.pathname === "/") return true;
return !!auth;
}
}
});
function providers() {
const providers = []
if (process.env.DISCORD_ID && process.env.DISCORD_SECRET) {
providers.push(Discord({
clientId: process.env.DISCORD_ID,
clientSecret: process.env.DISCORD_SECRET,
profile(profile) {
return {
id: profile.id,
name: profile.global_name,
email: profile.email,
image: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}?size=256`
}
}
}));
}
if (process.env.SLACK_ID && process.env.SLACK_SECRET) {
providers.push(Slack({
clientId: process.env.SLACK_ID,
clientSecret: process.env.SLACK_SECRET,
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: null
}
}
}));
}
if (process.env.GITHUB_ID && process.env.GITHUB_SECRET) {
providers.push(GitHub({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
profile(profile) {
return {
id: profile.id.toString(),
name: profile.name,
email: profile.email,
image: profile.avatar_url,
}
}
}));
}
return providers;
}