fix: trusted origins list not being respsected

This commit is contained in:
Bereket Engida
2024-11-20 18:42:17 +03:00
parent 186ace3b15
commit d14989c5bd
4 changed files with 7 additions and 10 deletions

View File

@@ -41,7 +41,7 @@ export const auth = betterAuth({
appName: "Better Auth Demo", appName: "Better Auth Demo",
database: { database: {
dialect, dialect,
type: "mysql", type: process.env.USE_MYSQL ? "mysql" : "sqlite",
}, },
session: { session: {
cookieCache: { cookieCache: {

View File

@@ -44,7 +44,7 @@ export const forgetPassword = createAuthEndpoint(
* error=INVALID_TOKEN`. If the token is valid, it'll be redirected with a query parameter `? * error=INVALID_TOKEN`. If the token is valid, it'll be redirected with a query parameter `?
* token=VALID_TOKEN * token=VALID_TOKEN
*/ */
redirectTo: z.string(), redirectTo: z.string().optional(),
}), }),
}, },
async (ctx) => { async (ctx) => {

View File

@@ -12,7 +12,6 @@ import type {
} from "../../types"; } from "../../types";
import type { toZod } from "../../types/to-zod"; import type { toZod } from "../../types/to-zod";
import { parseUserInput } from "../../db/schema"; import { parseUserInput } from "../../db/schema";
import { getDate } from "../../utils/date";
export const signUpEmail = <O extends BetterAuthOptions>() => export const signUpEmail = <O extends BetterAuthOptions>() =>
createAuthEndpoint( createAuthEndpoint(

View File

@@ -25,13 +25,11 @@ export const betterAuth = <O extends BetterAuthOptions>(options: O) => {
ctx.options.baseURL = baseURL; ctx.options.baseURL = baseURL;
ctx.baseURL = baseURL; ctx.baseURL = baseURL;
} }
ctx.trustedOrigins.push(url.origin); ctx.trustedOrigins = [
if (!ctx.options.baseURL) { ...(options.trustedOrigins || []),
return new Response("Base URL not set", { status: 400 }); ctx.baseURL,
} url.origin,
if (url.pathname === basePath || url.pathname === `${basePath}/`) { ];
return new Response("Welcome to BetterAuth", { status: 200 });
}
const { handler } = router(ctx, options); const { handler } = router(ctx, options);
return handler(request); return handler(request);
}, },