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",
database: {
dialect,
type: "mysql",
type: process.env.USE_MYSQL ? "mysql" : "sqlite",
},
session: {
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 `?
* token=VALID_TOKEN
*/
redirectTo: z.string(),
redirectTo: z.string().optional(),
}),
},
async (ctx) => {

View File

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

View File

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