From d014ac1ed354022edfb6617ee01d692d1b9fc8e4 Mon Sep 17 00:00:00 2001 From: JeongwooSeo Date: Tue, 1 Sep 2026 23:27:27 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20jwt=20=EC=BD=9C=EB=B0=B1=EC=97=90?= =?UTF-8?q?=EC=84=9C=20GitHub=20=EC=9B=90=EB=B3=B8=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=EC=9D=84=20account.profile=20=EB=8C=80=EC=8B=A0=20pro?= =?UTF-8?q?file=20=EC=9D=B8=EC=9E=90=EB=A1=9C=20=EC=9D=BD=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit next-auth v4 GitHub OAuth 플로우는 원본 프로필(login, id, bio 등)을 account에 넣지 않고 jwt 콜백의 별도 인자(profile)로 전달한다 (node_modules/next-auth/core/routes/callback.js 확인). account.profile은 항상 undefined였기 때문에 token.githubId가 로그인 시점에도 채워진 적이 없었고, 그 결과 ADMIN_GITHUB_ID를 아무리 정확히 설정해도 session.isAdmin이 항상 false였다. 리팩토링 전 원본 코드에도 동일한 버그가 있었으나 관리자 판정을 session.user.email로 하던 시절엔 드러나지 않았었다. Co-Authored-By: Claude Sonnet 5 --- app/lib/auth.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/lib/auth.ts b/app/lib/auth.ts index 90047b7..b7ad6fd 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -24,14 +24,16 @@ export const authOptions: NextAuthOptions = { async signIn() { return true; }, - async jwt({ token, account }) { - if (account?.profile) { - const profile = account.profile as GitHubProfile; - token.githubLogin = profile.login; - token.githubId = profile.id; - token.githubBio = profile.bio; - token.githubCompany = profile.company; - token.githubLocation = profile.location; + async jwt({ token, profile }) { + // next-auth의 GitHub OAuth 플로우는 원본 프로필을 account가 아니라 + // 이 콜백의 별도 인자(profile)로 전달한다 (로그인 시점에만 존재). + if (profile) { + const githubProfile = profile as unknown as GitHubProfile; + token.githubLogin = githubProfile.login; + token.githubId = githubProfile.id; + token.githubBio = githubProfile.bio; + token.githubCompany = githubProfile.company; + token.githubLocation = githubProfile.location; } return token; },