-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
38 lines (36 loc) · 1 KB
/
auth.ts
File metadata and controls
38 lines (36 loc) · 1 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
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { handlers, auth } = NextAuth({
providers: [
GitHub({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
allowDangerousEmailAccountLinking: true,
}),
],
pages: {
signIn: "/",
},
callbacks: {
async jwt({ token, account }) {
if (account) {
token.accessToken = account.access_token;
token.login = account.providerAccountId;
}
return token;
},
async session({ session, token }: any) {
session.accessToken = token.accessToken as string | undefined;
session.user.login = token.login as string | undefined;
return session;
},
async authorized({ request, auth }) {
const { pathname } = request.nextUrl;
// /write, /api/posts는 로그인 필요
if (pathname.startsWith("/write") || pathname.startsWith("/api/posts")) {
return !!auth;
}
return true;
},
},
});