Przeglądaj źródła

update auth

main
Steve Ruiz 4 lat temu
rodzic
commit
fdf82d3a91
2 zmienionych plików z 16 dodań i 7 usunięć
  1. 9
    0
      pages/api/auth/[...nextauth].ts
  2. 7
    7
      pages/auth-test.tsx

+ 9
- 0
pages/api/auth/[...nextauth].ts Wyświetl plik

7
     Providers.GitHub({
7
     Providers.GitHub({
8
       clientId: process.env.GITHUB_ID,
8
       clientId: process.env.GITHUB_ID,
9
       clientSecret: process.env.GITHUB_SECRET,
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
   callbacks: {
21
   callbacks: {

+ 7
- 7
pages/auth-test.tsx Wyświetl plik

49
 }
49
 }
50
 
50
 
51
 export async function getServerSideProps(context: GetServerSidePropsContext) {
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
   const sponsors = await fetch(
56
   const sponsors = await fetch(
57
     'https://sponsors.trnck.dev/sponsors/steveruizok'
57
     'https://sponsors.trnck.dev/sponsors/steveruizok'
58
   ).then((d) => d.json().then((d) => d.sponsors))
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
   console.log(
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
   return {
70
   return {

Ładowanie…
Anuluj
Zapisz