|
1 | | -import NextAuth, { type DefaultSession } from "next-auth" |
| 1 | +import NextAuth from "next-auth" |
2 | 2 | import Credentials from "next-auth/providers/credentials" |
3 | 3 | import GitHub from "next-auth/providers/github" |
4 | 4 | import { SiweMessage } from "siwe" |
5 | 5 |
|
6 | 6 | import { getUserIdByWallet, storeUser } from "@/lib/data/kv" |
7 | | - |
8 | | -declare module "next-auth" { |
9 | | - interface Session extends DefaultSession { |
10 | | - user: { |
11 | | - id: string |
12 | | - walletAddress?: string | null |
13 | | - githubId?: string | null |
14 | | - } & DefaultSession["user"] |
15 | | - } |
16 | | -} |
17 | | - |
18 | | -declare module "next-auth/jwt" { |
19 | | - interface JWT { |
20 | | - id?: string |
21 | | - walletAddress?: string | null |
22 | | - githubId?: string | null |
23 | | - } |
24 | | -} |
25 | | - |
26 | 7 | function getCsrfTokenFromRequest(request: Request) { |
27 | 8 | const cookieHeader = request.headers.get("cookie") |
28 | 9 | if (!cookieHeader) return undefined |
@@ -146,11 +127,28 @@ export const { |
146 | 127 |
|
147 | 128 | if (account?.provider === "github" && profile) { |
148 | 129 | const profileId = String(profile.id) |
| 130 | + const profileData = profile as { |
| 131 | + name?: string | null |
| 132 | + login?: string | null |
| 133 | + email?: string | null |
| 134 | + avatar_url?: string | null |
| 135 | + } |
| 136 | + |
149 | 137 | token.id = profileId |
150 | 138 | token.githubId = profileId |
151 | | - token.name = profile.name ?? profile.login ?? token.name |
152 | | - token.email = profile.email ?? token.email |
153 | | - token.picture = (profile as { avatar_url?: string })?.avatar_url ?? token.picture |
| 139 | + |
| 140 | + const profileName = profileData.name ?? profileData.login |
| 141 | + if (profileName) { |
| 142 | + token.name = profileName |
| 143 | + } |
| 144 | + |
| 145 | + if (profileData.email) { |
| 146 | + token.email = profileData.email |
| 147 | + } |
| 148 | + |
| 149 | + if (profileData.avatar_url) { |
| 150 | + token.picture = profileData.avatar_url |
| 151 | + } |
154 | 152 |
|
155 | 153 | await storeUser({ |
156 | 154 | id: profileId, |
|
0 commit comments