[GH-ISSUE #482] Apple SignIn with Identity Token: Cannot destructure property 'kid' #16918

Closed
opened 2026-04-15 14:53:06 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @abegehr on GitHub (Nov 10, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/482

Describe the bug
When trying to sign-in apple with identity token, I'm getting the following error:

TypeError: Cannot destructure property 'kid' of 'i.header' as it is undefined.
    at Object.verifyIdToken (file:node_modules/.pnpm/better-auth@0.8.1/node_modules/better-auth/dist/index.js:3:6048)

Looking at the code, it seems to be this statement: 88369eb3db/packages/better-auth/src/social-providers/apple.ts (L90-L93)

To Reproduce

Using the following statement to call sign-in with apple:

      const res = await auth.signIn.social({
        provider: "apple",
        idToken: {
          token: result.identityToken,
          nonce: nonce,
        }
      });

Expected behavior

I would expect the JWT identityToken to be properly decoded. Converting the token with https://jwt.io, it does provide the kid header.

Desktop (please complete the following information):

  • OS: macOS 15.1
  • Browser Safari
  • Version 18.1

Smartphone (please complete the following information):

  • Device: iPhone 12 Pro
  • OS: iOS 18.1
  • Browser Safari
Originally created by @abegehr on GitHub (Nov 10, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/482 **Describe the bug** When trying to sign-in apple with identity token, I'm getting the following error: ``` TypeError: Cannot destructure property 'kid' of 'i.header' as it is undefined. at Object.verifyIdToken (file:node_modules/.pnpm/better-auth@0.8.1/node_modules/better-auth/dist/index.js:3:6048) ``` Looking at the code, it seems to be this statement: https://github.com/better-auth/better-auth/blob/88369eb3db800e96dd29e8b4b4d7f9b7cdbbcc21/packages/better-auth/src/social-providers/apple.ts#L90-L93 **To Reproduce** Using the following statement to call sign-in with apple: ```ts const res = await auth.signIn.social({ provider: "apple", idToken: { token: result.identityToken, nonce: nonce, } }); ``` **Expected behavior** I would expect the JWT identityToken to be properly decoded. Converting the token with <https://jwt.io>, it does provide the kid header. **Desktop (please complete the following information):** - OS: macOS 15.1 - Browser Safari - Version 18.1 **Smartphone (please complete the following information):** - Device: iPhone 12 Pro - OS: iOS 18.1 - Browser Safari
GiteaMirror added the locked label 2026-04-15 14:53:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16918