[GH-ISSUE #3027] @better-auth/expo doubles options.trustedOrigins in ctx.context.options.trustedOrigins when used in custom plugin #9437

Closed
opened 2026-04-13 04:54:11 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @nkoynov on GitHub (Jun 14, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3027

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a backend
  2. Initialise betterAuth with @better-auth/expo plugin
  3. Add trustedOrigins option
  4. Create a customPlugin to log ctx.context.options.trustedOrigins
import { betterAuth } from 'better-auth';
import { expo } from '@better-auth/expo';

export const customPlugin = () => {
  return {
    id: 'customPlugin',
    endpoints: {
      customPluginEndpoint: createAuthEndpoint(
        '/custom-plugin/endpoint',
        { method: 'POST' },
        async (ctx) => {
          // will show in console (I guess the "http://localhost:8080" is added because I'm running the server on port 8080)
          // [ "http://localhost:3000", "http://localhost:3001", "myapp://", "http://localhost:8080",
          // "http://localhost:3000", "http://localhost:3001", "myapp://", "exp://" ]
          console.log(ctx.context.options.trustedOrigins);
        },
      ),
    },
  };
};

export const auth = betterAuth({
  trustedOrigins: ['http://localhost:3000', 'http://localhost:3001', 'myapp://'],
  plugins: [expo(), customPlugin()],
});

Current vs. Expected behavior

In our custom plugin, reading ctx.context.options.trustedOrigins yields each origin twice:

[
  "http://localhost:3000",
  "http://localhost:3001",
  "myapp://",
  "http://localhost:8080",
  "http://localhost:3000",
  "http://localhost:3001",
  "myapp://",
  "exp://"
]

Expected Behavior
Each origin should appear only once:

[
  "http://localhost:3000",
  "http://localhost:3001",
  "myapp://",
  "http://localhost:8080",
  "exp://"
]

What version of Better Auth are you using?

1.2.9

Provide environment information

- OS: 15.5
- Browser: Chrome

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

Backend

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { expo } from '@better-auth/expo';

export const customPlugin = () => {
  return {
    id: 'customPlugin',
    endpoints: {
      customPluginEndpoint: createAuthEndpoint(
        '/custom-plugin/endpoint',
        { method: 'POST' },
        async (ctx) => {
          console.log(ctx.context.options.trustedOrigins);
        },
      ),
    },
  };
};

export const auth = betterAuth({
  trustedOrigins: ['http://localhost:3000', 'http://localhost:3001', 'myapp://'],
  plugins: [expo(), customPlugin()],
});

Additional context

No response

Originally created by @nkoynov on GitHub (Jun 14, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3027 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a backend 2. Initialise `betterAuth` with `@better-auth/expo` plugin 3. Add `trustedOrigins` option 4. Create a `customPlugin` to log `ctx.context.options.trustedOrigins` ```typescript import { betterAuth } from 'better-auth'; import { expo } from '@better-auth/expo'; export const customPlugin = () => { return { id: 'customPlugin', endpoints: { customPluginEndpoint: createAuthEndpoint( '/custom-plugin/endpoint', { method: 'POST' }, async (ctx) => { // will show in console (I guess the "http://localhost:8080" is added because I'm running the server on port 8080) // [ "http://localhost:3000", "http://localhost:3001", "myapp://", "http://localhost:8080", // "http://localhost:3000", "http://localhost:3001", "myapp://", "exp://" ] console.log(ctx.context.options.trustedOrigins); }, ), }, }; }; export const auth = betterAuth({ trustedOrigins: ['http://localhost:3000', 'http://localhost:3001', 'myapp://'], plugins: [expo(), customPlugin()], }); ``` ### Current vs. Expected behavior In our custom plugin, reading ctx.context.options.trustedOrigins yields each origin twice: ```typescript [ "http://localhost:3000", "http://localhost:3001", "myapp://", "http://localhost:8080", "http://localhost:3000", "http://localhost:3001", "myapp://", "exp://" ] ``` Expected Behavior Each origin should appear only once: ```typescript [ "http://localhost:3000", "http://localhost:3001", "myapp://", "http://localhost:8080", "exp://" ] ``` ### What version of Better Auth are you using? 1.2.9 ### Provide environment information ```bash - OS: 15.5 - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { expo } from '@better-auth/expo'; export const customPlugin = () => { return { id: 'customPlugin', endpoints: { customPluginEndpoint: createAuthEndpoint( '/custom-plugin/endpoint', { method: 'POST' }, async (ctx) => { console.log(ctx.context.options.trustedOrigins); }, ), }, }; }; export const auth = betterAuth({ trustedOrigins: ['http://localhost:3000', 'http://localhost:3001', 'myapp://'], plugins: [expo(), customPlugin()], }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:54:11 -05:00
Author
Owner

@nkoynov commented on GitHub (Jun 21, 2025):

closed in 9801d1be

<!-- gh-comment-id:2993384157 --> @nkoynov commented on GitHub (Jun 21, 2025): closed in [9801d1be](https://github.com/better-auth/better-auth/commit/9801d1be)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9437