Error: Unauthorized request from https://appleid.apple.com with Expo API Routes #2857

Closed
opened 2026-03-13 10:23:58 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @samchouse on GitHub (Feb 10, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create an Expo backend following the docs.
  2. Try to sign in with Apple.
  3. Observe

Current vs. Expected behavior

Currently I get an error when returning from an Apple Sign-In:

Error: Unauthorized request from https://appleid.apple.com. This may happen because of a conflicting browser extension to intercept HTTP requests. Disable browser extensions or use incognito mode and try again.
    at /home/sam/Documents/projects/school/ski-buddy/node_modules/@expo/cli/src/start/server/middleware/CorsMiddleware.ts:51:11
    at call (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:239:7)
    at next (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:183:5)
    at /home/sam/Documents/projects/school/ski-buddy/node_modules/@expo/cli/src/start/server/middleware/ContextModuleSourceMapsMiddleware.ts:16:16
    at call (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:239:7)
    at next (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:183:5)
    at middleware (/home/sam/Documents/projects/school/ski-buddy/node_modules/@expo/cli/src/start/server/middleware/ExpoMiddleware.ts:62:16)
    at call (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:239:7)
    at next (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:183:5)
    at app.handle (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:186:3)

I'd expect it to respect my trustedOrigins and work.

What version of Better Auth are you using?

1.4.18

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1-NixOS SMP PREEMPT_DYNAMIC Fri Jan 30 09:32:28 UTC 2026",
    "release": "6.18.8",
    "cpuCount": 20,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-12700F",
    "totalMemory": "62.65 GB",
    "freeMemory": "30.60 GB"
  },
  "node": {
    "version": "v25.2.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.2.0"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.18.0"
    },
    {
      "name": "drizzle",
      "version": "^0.45.1"
    }
  ],
  "betterAuth": {
    "version": "Unknown",
    "config": null,
    "error": "Invalid environment variables"
  }
}

Which area(s) are affected? (Select all that apply)

Backend, Package

Auth config (if applicable)

import { expo } from "@better-auth/expo";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { env } from "@/env";
import { db } from "./db";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    usePlural: true,
  }),
  plugins: [expo()],
  socialProviders: {
    apple: {
      clientId: env.APPLE_CLIENT_ID,
      clientSecret: env.APPLE_CLIENT_SECRET,
      appBundleIdentifier: "..."
    },
  },
  trustedOrigins: ["https://appleid.apple.com", "ski-buddy://"],
  experimental: { joins: true },
});

Additional context

I have the server behind a Cloudflare Tunnel if it makes a difference.

Originally created by @samchouse on GitHub (Feb 10, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create an Expo backend following the docs. 2. Try to sign in with Apple. 3. Observe ### Current vs. Expected behavior Currently I get an error when returning from an Apple Sign-In: ``` Error: Unauthorized request from https://appleid.apple.com. This may happen because of a conflicting browser extension to intercept HTTP requests. Disable browser extensions or use incognito mode and try again. at /home/sam/Documents/projects/school/ski-buddy/node_modules/@expo/cli/src/start/server/middleware/CorsMiddleware.ts:51:11 at call (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:239:7) at next (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:183:5) at /home/sam/Documents/projects/school/ski-buddy/node_modules/@expo/cli/src/start/server/middleware/ContextModuleSourceMapsMiddleware.ts:16:16 at call (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:239:7) at next (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:183:5) at middleware (/home/sam/Documents/projects/school/ski-buddy/node_modules/@expo/cli/src/start/server/middleware/ExpoMiddleware.ts:62:16) at call (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:239:7) at next (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:183:5) at app.handle (/home/sam/Documents/projects/school/ski-buddy/node_modules/connect/index.js:186:3) ``` I'd expect it to respect my `trustedOrigins` and work. ### What version of Better Auth are you using? 1.4.18 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1-NixOS SMP PREEMPT_DYNAMIC Fri Jan 30 09:32:28 UTC 2026", "release": "6.18.8", "cpuCount": 20, "cpuModel": "12th Gen Intel(R) Core(TM) i7-12700F", "totalMemory": "62.65 GB", "freeMemory": "30.60 GB" }, "node": { "version": "v25.2.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "react", "version": "19.2.0" } ], "databases": [ { "name": "pg", "version": "^8.18.0" }, { "name": "drizzle", "version": "^0.45.1" } ], "betterAuth": { "version": "Unknown", "config": null, "error": "Invalid environment variables" } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Package ### Auth config (if applicable) ```typescript import { expo } from "@better-auth/expo"; import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { env } from "@/env"; import { db } from "./db"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", usePlural: true, }), plugins: [expo()], socialProviders: { apple: { clientId: env.APPLE_CLIENT_ID, clientSecret: env.APPLE_CLIENT_SECRET, appBundleIdentifier: "..." }, }, trustedOrigins: ["https://appleid.apple.com", "ski-buddy://"], experimental: { joins: true }, }); ``` ### Additional context I have the server behind a Cloudflare Tunnel if it makes a difference.
GiteaMirror added the expobug labels 2026-03-13 10:23:58 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Feb 10, 2026):

It seems you're encountering an "Unauthorized request" error while trying to sign in with Apple using your Expo backend. Based on the provided context, there are several potential causes and solutions you can explore:

  1. Trusted Origins: Ensure that https://appleid.apple.com is included in the trustedOrigins array in your configuration, which you have done correctly.

  2. Localhost and Non-HTTPS Restrictions: Apple Sign In does not support localhost or non-HTTPS URLs for callbacks. Make sure you are using a secure HTTPS domain rather than http://localhost.

  3. Client ID and Client Secret: Verify that you are using the correct clientId and clientSecret for Apple Sign In. For iOS native applications, the clientId should be the app's bundle ID, not the service ID [12].

  4. Disable Browser Extensions: Sometimes, browser extensions can interfere with authentication requests. It may help to disable any extensions or try using incognito mode.

  5. Inspect Network Requests: Use your browser's developer tools to inspect the network requests being sent to ensure they conform to Apple’s authentication flow.

If you continue to face issues, consider tagging the Better Auth team members, Beka and Max (@bekacru and @ping__), in your follow-up for more specific guidance.

Is there anything else you would like to dive into regarding this issue?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Feb 10, 2026): It seems you're encountering an "Unauthorized request" error while trying to sign in with Apple using your Expo backend. Based on the provided context, there are several potential causes and solutions you can explore: 1. **Trusted Origins**: Ensure that `https://appleid.apple.com` is included in the `trustedOrigins` array in your configuration, which you have done correctly. 2. **Localhost and Non-HTTPS Restrictions**: Apple Sign In does not support localhost or non-HTTPS URLs for callbacks. Make sure you are using a secure HTTPS domain rather than `http://localhost`. 3. **Client ID and Client Secret**: Verify that you are using the correct `clientId` and `clientSecret` for Apple Sign In. For iOS native applications, the `clientId` should be the app's bundle ID, not the service ID [[12]](https://www.better-auth.com/docs/authentication/apple). 4. **Disable Browser Extensions**: Sometimes, browser extensions can interfere with authentication requests. It may help to disable any extensions or try using incognito mode. 5. **Inspect Network Requests**: Use your browser's developer tools to inspect the network requests being sent to ensure they conform to Apple’s authentication flow. If you continue to face issues, consider tagging the Better Auth team members, Beka and Max (@bekacru and @ping__), in your follow-up for more specific guidance. Is there anything else you would like to dive into regarding this issue? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@samchouse commented on GitHub (Feb 10, 2026):

Everything mentioned in the basic debugging is already taken care of, not that I think it makes a difference. The request doesn't even make it to the Expo plugin. I added some console logs to debug and the error happened first so I doubt that trustedOrigins is being applied properly.

cc @Bekacru

@samchouse commented on GitHub (Feb 10, 2026): Everything mentioned in the basic debugging is already taken care of, not that I think it makes a difference. The request doesn't even make it to the Expo plugin. I added some console logs to debug and the error happened first so I doubt that `trustedOrigins` is being applied properly. cc @Bekacru
Author
Owner

@samchouse commented on GitHub (Feb 16, 2026):

Moved off of Expo API routes

@samchouse commented on GitHub (Feb 16, 2026): Moved off of Expo API routes
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2857