[PR #6420] fix(expo): Due to an incorrect type of the copied request object, the… #32255

Open
opened 2026-04-17 23:05:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6420
Author: @GuangZhouzhu
Created: 11/30/2025
Status: 🔄 Open

Base: mainHead: fix/expo-clone-req


📝 Commits (1)

  • fe6553e fix(expo): Due to an incorrect type of the copied request object, the subsequent logic did not use this duplicated object which had the origin field added. This resulted in the MISSING_OR_NULL_ORIGIN error.

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 packages/expo/src/index.ts (+1 -1)

📄 Description

Due to an incorrect type of the copied request object, the subsequent logic did not use this duplicated object which had the origin field added. This resulted in the MISSING_OR_NULL_ORIGIN error.

Based on my investigation so far, the affected logic is within the handler method returned by the createRouter function in the better-call package source code at line 248. Here is the relevant source code:

return {
    handler: async (request: Request) => {
        const onReq = await config?.onRequest?.(request);
        if (onReq instanceof Response) {
            return onReq;
        }
        // onReq instanceof Request = false, so req = request
        const req = onReq instanceof Request ? onReq : request;
        const res = await processRequest(req);
        const onRes = await config?.onResponse?.(res);
        if (onRes instanceof Response) {
            return onRes;
        }
        return res;
    },
    endpoints,
};

Please note this line of code: const req = onReq instanceof Request ? onReq : request;

The root cause is that the req object, which was previously created using const req = request.clone();, was not of the Request type. Consequently, the type check onReq instanceof Request in better-call evaluated to false. This forced the handler to fall back to using the original request object instead of the onReq object that contained the added origin field.

As a result, the originCheckMiddleware could not detect the origin field in the request, ultimately throwing the "Missing or null Origin" error.

link issue: #5536 #6257


Summary by cubic

Fix origin header handling in Expo by creating a real Request (new Request(request)) instead of using request.clone(). This ensures the better-call router uses the modified request and resolves MISSING_OR_NULL_ORIGIN errors.

Written for commit fe6553e2c7. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6420 **Author:** [@GuangZhouzhu](https://github.com/GuangZhouzhu) **Created:** 11/30/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/expo-clone-req` --- ### 📝 Commits (1) - [`fe6553e`](https://github.com/better-auth/better-auth/commit/fe6553e2c7a40b6e69995ffce5ff9a80291bc054) fix(expo): Due to an incorrect type of the copied request object, the subsequent logic did not use this duplicated object which had the origin field added. This resulted in the MISSING_OR_NULL_ORIGIN error. ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/expo/src/index.ts` (+1 -1) </details> ### 📄 Description Due to an incorrect type of the copied request object, the subsequent logic did not use this duplicated object which had the origin field added. This resulted in the MISSING_OR_NULL_ORIGIN error. Based on my investigation so far, the affected logic is within the handler method returned by the createRouter function in the better-call package [source code at line 248](https://github.com/Bekacru/better-call/blob/main/src/router.ts#L248). Here is the relevant source code: ```ts return { handler: async (request: Request) => { const onReq = await config?.onRequest?.(request); if (onReq instanceof Response) { return onReq; } // onReq instanceof Request = false, so req = request const req = onReq instanceof Request ? onReq : request; const res = await processRequest(req); const onRes = await config?.onResponse?.(res); if (onRes instanceof Response) { return onRes; } return res; }, endpoints, }; ``` Please note this line of code: `const req = onReq instanceof Request ? onReq : request;` The root cause is that the req object, which was previously created using `const req = request.clone();`, was not of the Request type. Consequently, the type check onReq instanceof Request in better-call evaluated to false. This forced the handler to fall back to using the original request object instead of the onReq object that contained the added origin field. As a result, the originCheckMiddleware could not detect the origin field in the request, ultimately throwing the "Missing or null Origin" error. link issue: #5536 #6257 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix origin header handling in Expo by creating a real Request (new Request(request)) instead of using request.clone(). This ensures the better-call router uses the modified request and resolves MISSING_OR_NULL_ORIGIN errors. <sup>Written for commit fe6553e2c7a40b6e69995ffce5ff9a80291bc054. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 23:05:52 -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#32255