소스 검색

update auth

main
Steve Ruiz 4 년 전
부모
커밋
fdf82d3a91
2개의 변경된 파일16개의 추가작업 그리고 7개의 파일을 삭제
  1. 9
    0
      pages/api/auth/[...nextauth].ts
  2. 7
    7
      pages/auth-test.tsx

+ 9
- 0
pages/api/auth/[...nextauth].ts 파일 보기

@@ -7,6 +7,15 @@ const options = {
7 7
     Providers.GitHub({
8 8
       clientId: process.env.GITHUB_ID,
9 9
       clientSecret: process.env.GITHUB_SECRET,
10
+      profile(profile) {
11
+        return {
12
+          id: profile.id,
13
+          login: profile.login,
14
+          name: profile.name || profile.login,
15
+          email: profile.email,
16
+          image: profile.avatar_url,
17
+        } as any
18
+      },
10 19
     }),
11 20
   ],
12 21
   callbacks: {

+ 7
- 7
pages/auth-test.tsx 파일 보기

@@ -49,22 +49,22 @@ export default function Home({
49 49
 }
50 50
 
51 51
 export async function getServerSideProps(context: GetServerSidePropsContext) {
52
-  const session = await getSession(context)
52
+  const session: any = await getSession(context)
53 53
 
54
-  const id = session?.user?.image.match(/u\/(.*)\?/)?.[1]
54
+  const handle = session?.user?.login
55 55
 
56 56
   const sponsors = await fetch(
57 57
     'https://sponsors.trnck.dev/sponsors/steveruizok'
58 58
   ).then((d) => d.json().then((d) => d.sponsors))
59 59
 
60
-  const sponsor = sponsors.find((sponsor: { avatar: string }) =>
61
-    sponsor.avatar.includes(id)
60
+  const sponsor = sponsors.some(
61
+    (sponsor: { handle: string }) => sponsor.handle === handle
62 62
   )
63 63
 
64 64
   console.log(
65
-    session?.user,
66
-    id,
67
-    sponsors.map((sponsor: any) => sponsor.avatar)
65
+    session,
66
+    handle,
67
+    sponsors.map((sponsor: any) => sponsor.handle)
68 68
   )
69 69
 
70 70
   return {

Loading…
취소
저장