[GH-ISSUE #7078] trustedOrigins request is undefined using Hono after upgrading to 1.4.9 from 1.4.7 #10722

Closed
opened 2026-04-13 07:01:56 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @SamJbori on GitHub (Jan 1, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7078

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I have a turbo repo project where I have my server app using Hono and an api package where my better-auth config is

Current vs. Expected behavior

 trustedOrigins: (request) => {
      // Return an array of trusted origins based on the request
      const origin = request?.headers.get("origin");

      console.log("Origin: ", origin);
      return [origin];
    },

Expected
[string]

Seen
[undefined]

What version of Better Auth are you using?

1.4.9

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1 (2025-11-05)",
    "release": "6.12.57+deb13-amd64",
    "cpuCount": 32,
    "cpuModel": "13th Gen Intel(R) Core(TM) i9-13900K",
    "totalMemory": "93.48 GB",
    "freeMemory": "78.59 GB"
  },
  "node": {
    "version": "v22.21.1",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.3.4"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "1.4.9",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import type { DBCollections } from "@x3buntest/validators/db";
import type { BetterAuthOptions, InferSession, InferUser } from "better-auth";
import type { MongoClient } from "mongodb";
import { expo } from "@better-auth/expo";
import { mongodbAdapter } from "better-auth/adapters/mongodb";
import { betterAuth } from "better-auth/minimal";
import { anonymous, captcha, phoneNumber } from "better-auth/plugins";

import { dbNames } from "@x3buntest/validators/db";

import { dbCollection } from "./db";
import { env } from "./env";

export const initAuth = (dbClient: MongoClient) => {
  const db = dbClient.db(dbNames.auth);
  const collection = (collectionName: DBCollections) =>
    dbCollection(dbClient, collectionName);
  const authConfig = {
    database: mongodbAdapter(db),
    basePath: "/auth",
    advanced: {
      cookiePrefix: "myrepo",
      useSecureCookies: true,
      crossSubDomainCookies: {
        enabled: true,
        domain:
          env.NODE_ENV === "development" ? undefined : ".x3bun.vercel.app", //FIX // Domain with a leading period
      },
      defaultCookieAttributes: {
        secure: true,
        httpOnly: true,
        sameSite: "none", // Allows CORS-based cookie sharing across subdomains
        partitioned: true, // New browser standards will mandate this for foreign cookies
      },
    },
    trustedOrigins: (request) => {
      // Return an array of trusted origins based on the request
      const origin = request?.headers.get("origin");

      console.log("Origin: ", origin);
      return ["localhost", "dev.hamem.com"];
    },
    user: {
      additionalFields: {
        phoneNumber: {
          type: "string",
          required: true,
          unique: true,
          // Add your own validator
          // validator: { input: ZPhoneNumber, output: ZPhoneNumber },
        },
        phoneNumberVerified: {
          type: "boolean",
          required: false,
          defaultValue: false,
        },
        isAnonymous: { type: "boolean", required: false },
        // Use your own logic
        isAdmin: { type: "boolean", required: false },
        role: {
          type: "string",
          required: false,
          // Add youe own validator
          // validator: ZENUM
        },
      },
    },
    plugins: [
      anonymous({
        onLinkAccount({ anonymousUser, newUser }) {
          console.log("AnonymousUser: ", anonymousUser.user.id);
          console.log("NewUser: ", newUser.user.id);
          // do something, like change cart ownership, or likes
          void collection("Posts").findOne();
        },
      }),
      phoneNumber({
        sendOTP: ({ phoneNumber, code }) => {
          console.log("Code: ", phoneNumber, code);
        },
        expiresIn: 600,
        otpLength: 6,
        phoneNumberValidator: (_phoneNumber) => {
          // return ZPhoneNumber.safeParse(phoneNumber).success;
          return true;
        },
        signUpOnVerification: {
          getTempEmail: (phoneNumber) => {
            return `${phoneNumber}@my.myrepo.com`;
          },
          //optionally, you can also pass `getTempName` function to generate a temporary name for the user
          getTempName: (phoneNumber) => {
            return phoneNumber; //by default, it will use the phone number as the name
          },
        },
      }),
      captcha({
        provider: "cloudflare-turnstile", // or google-recaptcha, hcaptcha
        secretKey: env.CLOUDFLARE_TURNSTILE_SECRET_KEY,
        endpoints:
          env.NODE_ENV === "development"
            ? undefined
            : ["/phone-number/send-otp"],
      }),
      expo(),
    ] as BetterAuthOptions["plugins"],
    onAPIError: {
      onError(error, ctx) {
        console.error("BETTER AUTH API ERROR", error, ctx);
      },
    },
  } satisfies BetterAuthOptions;

  return betterAuth({ ...authConfig });
};
export type Auth = ReturnType<typeof initAuth>;
export type Session = InferSession<Auth>;
export type User = InferUser<Auth>;
export type AuthData = {
  session: Session;
  user: User;
} | null;

Additional context

No response

Originally created by @SamJbori on GitHub (Jan 1, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7078 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I have a turbo repo project where I have my server app using Hono and an api package where my `better-auth` config is ### Current vs. Expected behavior ```typescript trustedOrigins: (request) => { // Return an array of trusted origins based on the request const origin = request?.headers.get("origin"); console.log("Origin: ", origin); return [origin]; }, ``` **Expected** [string] **Seen** [undefined] ### What version of Better Auth are you using? 1.4.9 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1 (2025-11-05)", "release": "6.12.57+deb13-amd64", "cpuCount": 32, "cpuModel": "13th Gen Intel(R) Core(TM) i9-13900K", "totalMemory": "93.48 GB", "freeMemory": "78.59 GB" }, "node": { "version": "v22.21.1", "env": "development" }, "packageManager": { "name": "bun", "version": "1.3.4" }, "frameworks": null, "databases": null, "betterAuth": { "version": "1.4.9", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import type { DBCollections } from "@x3buntest/validators/db"; import type { BetterAuthOptions, InferSession, InferUser } from "better-auth"; import type { MongoClient } from "mongodb"; import { expo } from "@better-auth/expo"; import { mongodbAdapter } from "better-auth/adapters/mongodb"; import { betterAuth } from "better-auth/minimal"; import { anonymous, captcha, phoneNumber } from "better-auth/plugins"; import { dbNames } from "@x3buntest/validators/db"; import { dbCollection } from "./db"; import { env } from "./env"; export const initAuth = (dbClient: MongoClient) => { const db = dbClient.db(dbNames.auth); const collection = (collectionName: DBCollections) => dbCollection(dbClient, collectionName); const authConfig = { database: mongodbAdapter(db), basePath: "/auth", advanced: { cookiePrefix: "myrepo", useSecureCookies: true, crossSubDomainCookies: { enabled: true, domain: env.NODE_ENV === "development" ? undefined : ".x3bun.vercel.app", //FIX // Domain with a leading period }, defaultCookieAttributes: { secure: true, httpOnly: true, sameSite: "none", // Allows CORS-based cookie sharing across subdomains partitioned: true, // New browser standards will mandate this for foreign cookies }, }, trustedOrigins: (request) => { // Return an array of trusted origins based on the request const origin = request?.headers.get("origin"); console.log("Origin: ", origin); return ["localhost", "dev.hamem.com"]; }, user: { additionalFields: { phoneNumber: { type: "string", required: true, unique: true, // Add your own validator // validator: { input: ZPhoneNumber, output: ZPhoneNumber }, }, phoneNumberVerified: { type: "boolean", required: false, defaultValue: false, }, isAnonymous: { type: "boolean", required: false }, // Use your own logic isAdmin: { type: "boolean", required: false }, role: { type: "string", required: false, // Add youe own validator // validator: ZENUM }, }, }, plugins: [ anonymous({ onLinkAccount({ anonymousUser, newUser }) { console.log("AnonymousUser: ", anonymousUser.user.id); console.log("NewUser: ", newUser.user.id); // do something, like change cart ownership, or likes void collection("Posts").findOne(); }, }), phoneNumber({ sendOTP: ({ phoneNumber, code }) => { console.log("Code: ", phoneNumber, code); }, expiresIn: 600, otpLength: 6, phoneNumberValidator: (_phoneNumber) => { // return ZPhoneNumber.safeParse(phoneNumber).success; return true; }, signUpOnVerification: { getTempEmail: (phoneNumber) => { return `${phoneNumber}@my.myrepo.com`; }, //optionally, you can also pass `getTempName` function to generate a temporary name for the user getTempName: (phoneNumber) => { return phoneNumber; //by default, it will use the phone number as the name }, }, }), captcha({ provider: "cloudflare-turnstile", // or google-recaptcha, hcaptcha secretKey: env.CLOUDFLARE_TURNSTILE_SECRET_KEY, endpoints: env.NODE_ENV === "development" ? undefined : ["/phone-number/send-otp"], }), expo(), ] as BetterAuthOptions["plugins"], onAPIError: { onError(error, ctx) { console.error("BETTER AUTH API ERROR", error, ctx); }, }, } satisfies BetterAuthOptions; return betterAuth({ ...authConfig }); }; export type Auth = ReturnType<typeof initAuth>; export type Session = InferSession<Auth>; export type User = InferUser<Auth>; export type AuthData = { session: Session; user: User; } | null; ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 07:01:56 -05:00
Author
Owner

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

It seems you're experiencing an issue with the trustedOrigins being undefined in your Hono app after upgrading to Better Auth version 1.4.9.

Based on current discussions and resolved issues, here are a few steps you could take:

  1. Check for Undefined Request: Make sure that the request parameter in your trustedOrigins function is being passed correctly. If the request is undefined, you might want to handle that case by returning a default value or an empty array. This approach is suggested to stabilize the trustedOrigins logic [1].

  2. Explicitly Type the Parameter: Ensure that the parameter for the trustedOrigins callback is explicitly typed, as some recent updates might have changed how this is interpreted. The parameter can be defined as Request | undefined to improve type safety and prevent errors when the request is absent [2][5].

  3. Debugging: Log the incoming requests to see if they are being received as expected when the trustedOrigins function is executed. This will help you confirm if the issue lies with the requests not reaching the handler or with the processing within the function itself.

If you continue to face issues despite these adjustments, please tag the Better Auth team members @bekacru and @ping__ for more specialized assistance.

What specific steps have you tried so far, and do you have any further details that might help in debugging this issue?

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3703351984 --> @better-auth-agent[bot] commented on GitHub (Jan 1, 2026): It seems you're experiencing an issue with the `trustedOrigins` being `undefined` in your Hono app after upgrading to Better Auth version 1.4.9. Based on current discussions and resolved issues, here are a few steps you could take: 1. **Check for Undefined Request**: Make sure that the request parameter in your `trustedOrigins` function is being passed correctly. If the request is undefined, you might want to handle that case by returning a default value or an empty array. This approach is suggested to stabilize the `trustedOrigins` logic [[1]](https://github.com/better-auth/better-auth/pull/6888). 2. **Explicitly Type the Parameter**: Ensure that the parameter for the `trustedOrigins` callback is explicitly typed, as some recent updates might have changed how this is interpreted. The parameter can be defined as `Request | undefined` to improve type safety and prevent errors when the request is absent [[2]](https://github.com/better-auth/better-auth/issues/3027)[[5]](https://github.com/better-auth/better-auth/pull/6892). 3. **Debugging**: Log the incoming requests to see if they are being received as expected when the `trustedOrigins` function is executed. This will help you confirm if the issue lies with the requests not reaching the handler or with the processing within the function itself. If you continue to face issues despite these adjustments, please tag the Better Auth team members @bekacru and @ping__ for more specialized assistance. What specific steps have you tried so far, and do you have any further details that might help in debugging 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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Jan 1, 2026):

This is expected after upgrading to Better Auth 1.4.9: the trustedOrigins function can now receive undefined for the request parameter during initialization or direct API calls. Your function should always handle the case where request is undefined and return a default list of trusted origins. For example:

trustedOrigins: (request) => {
  if (!request) return ["localhost", "dev.hamem.com"];
  const origin = request.headers.get("origin");
  return [origin ?? "localhost"];
}

See docs and code changes

With Hono, there’s also an edge case: Hono’s request objects can have immutable headers or be pseudo-Requests, which sometimes causes the request to be missing or incomplete. If you’re using Expo or see issues with the origin header, add middleware to clone the request and set the origin header from expo-origin if present:

app.use("/auth/*", async (c, next) => {
  const expoOrigin = c.req.header("expo-origin");
  if (expoOrigin) {
    const newHeaders = new Headers(c.req.raw.headers);
    newHeaders.set("origin", expoOrigin);
    c.req.raw = new Request(c.req.raw, { headers: newHeaders });
  }
  await next();
});

See Hono/Expo workaround

Always check for undefined in your trustedOrigins function, and patch the request as above if you’re using Expo or Hono and need to ensure the origin header is present. This will keep your setup robust with Better Auth 1.4.9+.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3703355416 --> @dosubot[bot] commented on GitHub (Jan 1, 2026): <!-- Answer --> This is expected after upgrading to Better Auth 1.4.9: the `trustedOrigins` function can now receive `undefined` for the `request` parameter during initialization or direct API calls. Your function should always handle the case where `request` is undefined and return a default list of trusted origins. For example: ```ts trustedOrigins: (request) => { if (!request) return ["localhost", "dev.hamem.com"]; const origin = request.headers.get("origin"); return [origin ?? "localhost"]; } ``` [See docs and code changes](https://github.com/better-auth/better-auth/pull/6890) With Hono, there’s also an edge case: Hono’s request objects can have immutable headers or be pseudo-Requests, which sometimes causes the request to be missing or incomplete. If you’re using Expo or see issues with the `origin` header, add middleware to clone the request and set the `origin` header from `expo-origin` if present: ```ts app.use("/auth/*", async (c, next) => { const expoOrigin = c.req.header("expo-origin"); if (expoOrigin) { const newHeaders = new Headers(c.req.raw.headers); newHeaders.set("origin", expoOrigin); c.req.raw = new Request(c.req.raw, { headers: newHeaders }); } await next(); }); ``` [See Hono/Expo workaround](https://github.com/better-auth/better-auth/discussions/5750) Always check for `undefined` in your `trustedOrigins` function, and patch the request as above if you’re using Expo or Hono and need to ensure the `origin` header is present. This will keep your setup robust with Better Auth 1.4.9+. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9d722cbf-d874-4e92-a3cf-0f15d78f08af?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20expected%20after%20upgrading%20to%20Better%20Auth%201.4.9%3A%20the%20%60trustedOrigins%60%20function%20can%20now%20receive%20%60undefined%60%20for%20the%20%60request%60%20parameter%20during%20initialization%20or%20direct%20API%20calls.%20Your%20function%20should%20always%20handle%20the%20case%20where%20%60request%60%20is%20undefined%20and%20return%20a%20default%20list%20of%20trusted%20origins.%20For%20example%3A%0A%0A%60%60%60ts%0AtrustedOrigins%3A%20%28request%29%20%3D%3E%20%7B%0A%20%20if%20%28%21request%29%20return%20%5B%22localhost%22%2C%20%22dev.hamem.com%22%5D%3B%0A%20%20const%20origin%20%3D%20request.headers.get%28%22origin%22%29%3B%0A%20%20return%20%5Borigin%20%3F%3F%20%22localhost%22%5D%3B%0A%7D%0A%60%60%60%0A%5BSee%20docs%20and%20code%20changes%5D%28https%3A//github.com/better-auth/better-auth/pull/6890%29%0A%0AWith%20Hono%2C%20there%E2%80%99s%20also%20an%20edge%20case%3A%20Hono%E2%80%99s%20request%20objects%20can%20have%20immutable%20headers%20or%20be%20pseudo-Requests%2C%20which%20sometimes%20causes%20the%20request%20to%20be%20missing%20or%20incomplete.%20If%20you%E2%80%99re%20using%20Expo%20or%20see%20issues%20with%20the%20%60origin%60%20header%2C%20add%20middleware%20to%20clone%20the%20request%20and%20set%20the%20%60origin%60%20header%20from%20%60expo-origin%60%20if%20present%3A%0A%0A%60%60%60ts%0Aapp.use%28%22/auth/%2A%22%2C%20async%20%28c%2C%20next%29%20%3D%3E%20%7B%0A%20%20const%20expoOrigin%20%3D%20c.req.header%28%22expo-origin%22%29%3B%0A%20%20if%20%28expoOrigin%29%20%7B%0A%20%20%20%20const%20newHeaders%20%3D%20new%20Headers%28c.req.raw.headers%29%3B%0A%20%20%20%20newHeaders.set%28%22origin%22%2C%20expoOrigin%29%3B%0A%20%20%20%20c.req.raw%20%3D%20new%20Request%28c.req.raw%2C%20%7B%20headers%3A%20newHeaders%20%7D%29%3B%0A%20%20%7D%0A%20%20await%20next%28%29%3B%0A%7D%29%3B%0A%60%60%60%0A%5BSee%20Hono/Expo%20workaround%5D%28https%3A//github.com/better-auth/better-auth/discussions/5750%29%0A%0AAlways%20check%20for%20%60undefined%60%20in%20your%20%60trustedOrigins%60%20function%2C%20and%20patch%20the%20request%20as%20above%20if%20you%E2%80%99re%20using%20Expo%20or%20Hono%20and%20need%20to%20ensure%20the%20%60origin%60%20header%20is%20present.%20This%20will%20keep%20your%20setup%20robust%20with%20Better%20Auth%201.4.9%2B.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7078)
Author
Owner

@bytaesu commented on GitHub (Jan 1, 2026):

Hi @SamJbori,

When making requests to the Hono server through non-browser env (e.g. RSC), origin header is not automatically added.

https://github.com/user-attachments/assets/857dd6a4-8896-4983-b0f8-3f4951a5790e

<!-- gh-comment-id:3703529363 --> @bytaesu commented on GitHub (Jan 1, 2026): Hi @SamJbori, When making requests to the Hono server through non-browser env (e.g. RSC), origin header is not automatically added. https://github.com/user-attachments/assets/857dd6a4-8896-4983-b0f8-3f4951a5790e
Author
Owner

@uncomplexity commented on GitHub (Jan 2, 2026):

Image

request parameter type is still Request instead of Request | undefined

<!-- gh-comment-id:3704329410 --> @uncomplexity commented on GitHub (Jan 2, 2026): <img width="508" height="240" alt="Image" src="https://github.com/user-attachments/assets/ce8508f2-58c7-458d-94a9-de4f8e250f8f" /> request parameter type is still `Request` instead of `Request | undefined`
Author
Owner

@SamJbori commented on GitHub (Jan 3, 2026):

@dosu @dosubot @bytaesu
I am not using Expo

To give more context, I am creating a starter template and planning to make it available to public with create app command, I've not finished the Expo part integration yet.

<!-- gh-comment-id:3706739312 --> @SamJbori commented on GitHub (Jan 3, 2026): @dosu @dosubot @bytaesu I am not using `Expo` To give more context, I am creating a starter template and planning to make it available to public with `create` app command, I've not finished the `Expo` part integration yet.
Author
Owner

@dosubot[bot] commented on GitHub (Jan 3, 2026):

No Expo-specific workarounds are needed for your current setup. In Better Auth 1.4.9, it's expected that the trustedOrigins function can receive undefined for the request parameter—this happens during initialization or direct API calls. The type definition was updated to Request | undefined, so your implementation should always check for undefined before accessing request properties. For a robust starter template, use:

trustedOrigins: (request) => {
  if (!request) return ["http://localhost:3000", "https://your-public-domain.com"];
  const origin = request.headers.get("origin");
  // Optionally validate origin here
  return origin ? [origin] : [];
}

This pattern is now the recommended approach and is reflected in the latest docs and type definitions (PR #6892, PR #6890). For Hono, be aware that the request object may sometimes be a pseudo Request due to @hono/node-server, but maintainers are aware and working on compatibility improvements (issue). For CORS, make sure all frontend origins (including protocol and port) are explicitly listed in trustedOrigins, and run your CORS middleware before auth routes (discussion).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3706749543 --> @dosubot[bot] commented on GitHub (Jan 3, 2026): <!-- Answer --> No Expo-specific workarounds are needed for your current setup. In Better Auth 1.4.9, it's expected that the trustedOrigins function can receive undefined for the request parameter—this happens during initialization or direct API calls. The type definition was updated to Request | undefined, so your implementation should always check for undefined before accessing request properties. For a robust starter template, use: ```ts trustedOrigins: (request) => { if (!request) return ["http://localhost:3000", "https://your-public-domain.com"]; const origin = request.headers.get("origin"); // Optionally validate origin here return origin ? [origin] : []; } ``` This pattern is now the recommended approach and is reflected in the latest docs and type definitions ([PR #6892](https://github.com/better-auth/better-auth/pull/6892), [PR #6890](https://github.com/better-auth/better-auth/pull/6890)). For Hono, be aware that the request object may sometimes be a pseudo Request due to @hono/node-server, but maintainers are aware and working on compatibility improvements ([issue](https://github.com/better-auth/better-auth/issues/7014)). For CORS, make sure all frontend origins (including protocol and port) are explicitly listed in trustedOrigins, and run your CORS middleware before auth routes ([discussion](https://github.com/better-auth/better-auth/issues/3874)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/13ef39c3-7828-475e-8383-2ad610427267?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=No%20Expo-specific%20workarounds%20are%20needed%20for%20your%20current%20setup.%20In%20Better%20Auth%201.4.9%2C%20it%27s%20expected%20that%20the%20trustedOrigins%20function%20can%20receive%20undefined%20for%20the%20request%20parameter%E2%80%94this%20happens%20during%20initialization%20or%20direct%20API%20calls.%20The%20type%20definition%20was%20updated%20to%20Request%20%7C%20undefined%2C%20so%20your%20implementation%20should%20always%20check%20for%20undefined%20before%20accessing%20request%20properties.%20For%20a%20robust%20starter%20template%2C%20use%3A%0A%0A%60%60%60ts%0AtrustedOrigins%3A%20%28request%29%20%3D%3E%20%7B%0A%20%20if%20%28%21request%29%20return%20%5B%22http%3A//localhost%3A3000%22%2C%20%22https%3A//your-public-domain.com%22%5D%3B%0A%20%20const%20origin%20%3D%20request.headers.get%28%22origin%22%29%3B%0A%20%20//%20Optionally%20validate%20origin%20here%0A%20%20return%20origin%20%3F%20%5Borigin%5D%20%3A%20%5B%5D%3B%0A%7D%0A%60%60%60%0A%0AThis%20pattern%20is%20now%20the%20recommended%20approach%20and%20is%20reflected%20in%20the%20latest%20docs%20and%20type%20definitions%C2%A0%28%5BPR%20%236892%5D%28https%3A//github.com/better-auth/better-auth/pull/6892%29%2C%20%5BPR%20%236890%5D%28https%3A//github.com/better-auth/better-auth/pull/6890%29%29.%20For%20Hono%2C%20be%20aware%20that%20the%20request%20object%20may%20sometimes%20be%20a%20pseudo%20Request%20due%20to%20%40hono/node-server%2C%20but%20maintainers%20are%20aware%20and%20working%20on%20compatibility%20improvements%C2%A0%28%5Bissue%5D%28https%3A//github.com/better-auth/better-auth/issues/7014%29%29.%20For%20CORS%2C%20make%20sure%20all%20frontend%20origins%20%28including%20protocol%20and%20port%29%20are%20explicitly%20listed%20in%20trustedOrigins%2C%20and%20run%20your%20CORS%20middleware%20before%20auth%20routes%C2%A0%28%5Bdiscussion%5D%28https%3A//github.com/better-auth/better-auth/issues/3874%29%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7078)
Author
Owner

@bytaesu commented on GitHub (Jan 7, 2026):

Image

request parameter type is still Request instead of Request | undefined

I recently fixed it, and it’s resolved in the latest version 🙏

<!-- gh-comment-id:3717427053 --> @bytaesu commented on GitHub (Jan 7, 2026): > <img alt="Image" width="508" height="240" src="https://private-user-images.githubusercontent.com/179131442/531376662-ce8508f2-58c7-458d-94a9-de4f8e250f8f.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njc3NjUzOTUsIm5iZiI6MTc2Nzc2NTA5NSwicGF0aCI6Ii8xNzkxMzE0NDIvNTMxMzc2NjYyLWNlODUwOGYyLTU4YzctNDU4ZC05NGE5LWRlNGY4ZTI1MGY4Zi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMTA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDEwN1QwNTUxMzVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03NTFmMzBhMjc1ZDE4MzhkMzEzNDllNGQ1ZDdhYmU2ZTBiNDkxMGY2OGFjMTBmODQ2OWVlMTA0OTMwNGY4MGMxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.iI5mDQEJB4cw6519XaHoWH37tgZXtqIMhWK7qRhYSA4"> > > request parameter type is still `Request` instead of `Request | undefined` I recently fixed it, and it’s resolved in the latest version 🙏
Author
Owner

@bytaesu commented on GitHub (Jan 7, 2026):

I tested it but couldn’t reproduce the issue, so I’ll close it for now.
Feel free to mention me or reopen if the issue persists.

<!-- gh-comment-id:3717429833 --> @bytaesu commented on GitHub (Jan 7, 2026): I tested it but couldn’t reproduce the issue, so I’ll close it for now. Feel free to mention me or reopen if the issue persists.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10722