mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
fix: redirect middleware shouldn't check baseURL
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
"lint": "biome check .",
|
"lint": "biome check .",
|
||||||
"lint:fix": "biome check . --apply",
|
"lint:fix": "biome check . --apply",
|
||||||
"release": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --no-git-checks",
|
"release": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --no-git-checks",
|
||||||
"release:no-build": "bumpp && pnpm -r publish --access public --no-git-checks",
|
"release:no-build": "bumpp && pnpm -r publish --access public --no-git-checks --tag next",
|
||||||
"release:beta": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --tag next --no-git-checks",
|
"release:beta": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --tag next --no-git-checks",
|
||||||
"test": "turbo --filter \"./packages/*\" test",
|
"test": "turbo --filter \"./packages/*\" test",
|
||||||
"typecheck": "turbo --filter \"./packages/*\" typecheck"
|
"typecheck": "turbo --filter \"./packages/*\" typecheck"
|
||||||
|
|||||||
@@ -7,15 +7,14 @@ import { logger } from "../../utils/logger";
|
|||||||
* preventing open redirect attacks.
|
* preventing open redirect attacks.
|
||||||
*/
|
*/
|
||||||
export const redirectURLMiddleware = createAuthMiddleware(async (ctx) => {
|
export const redirectURLMiddleware = createAuthMiddleware(async (ctx) => {
|
||||||
const { body, query, headers, context } = ctx;
|
const { body, query, context } = ctx;
|
||||||
|
|
||||||
const callbackURL =
|
const callbackURL =
|
||||||
body?.callbackURL ||
|
body?.callbackURL ||
|
||||||
query?.callbackURL ||
|
query?.callbackURL ||
|
||||||
query?.redirectTo ||
|
query?.redirectTo ||
|
||||||
body?.redirectTo;
|
body?.redirectTo;
|
||||||
const currentURL =
|
const currentURL = query?.currentURL;
|
||||||
query?.currentURL || headers?.get("referer") || context.baseURL;
|
|
||||||
const trustedOrigins = context.trustedOrigins;
|
const trustedOrigins = context.trustedOrigins;
|
||||||
|
|
||||||
const validateURL = (url: string | undefined, label: string) => {
|
const validateURL = (url: string | undefined, label: string) => {
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ export const betterAuth = <O extends BetterAuthOptions>(options: O) => {
|
|||||||
getBaseURL(undefined, basePath) || `${url.origin}${basePath}`;
|
getBaseURL(undefined, basePath) || `${url.origin}${basePath}`;
|
||||||
ctx.options.baseURL = baseURL;
|
ctx.options.baseURL = baseURL;
|
||||||
ctx.baseURL = baseURL;
|
ctx.baseURL = baseURL;
|
||||||
ctx.trustedOrigins = [url.origin];
|
|
||||||
}
|
}
|
||||||
|
ctx.trustedOrigins = [url.origin, ...(ctx.options.trustedOrigins || [])];
|
||||||
if (!ctx.options.baseURL) {
|
if (!ctx.options.baseURL) {
|
||||||
return new Response("Base URL not set", { status: 400 });
|
return new Response("Base URL not set", { status: 400 });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user