fix: allow plugins to set email and password values (#1212)

This commit is contained in:
kzlar
2025-01-20 02:59:33 -05:00
committed by GitHub
parent b33b19ee0b
commit f61d862682
4 changed files with 50 additions and 10 deletions

View File

@@ -100,10 +100,6 @@ exports[`init > should match config 1`] = `
"open": true,
"readonly": false,
},
"emailAndPassword": {
"autoSignIn": true,
"enabled": false,
},
"plugins": [],
"secret": "better-auth-secret-123456789",
},

View File

@@ -204,7 +204,7 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
}
if (
!ctx.context.options.emailAndPassword.autoSignIn ||
ctx.context.options.emailAndPassword.autoSignIn === false ||
ctx.context.options.emailAndPassword.requireEmailVerification
) {
return ctx.json({

View File

@@ -98,4 +98,53 @@ describe("init", async () => {
ok: true,
});
});
it("should allow plugins to set config values", async () => {
const ctx = await init({
database,
baseURL: "http://localhost:3000",
plugins: [
{
id: "test-plugin",
init(ctx) {
return {
context: ctx,
options: {
emailAndPassword: {
enabled: true,
},
},
};
},
},
],
});
expect(ctx.options.emailAndPassword?.enabled).toBe(true);
});
it("should not allow plugins to set config values if theyre set in the main config", async () => {
const ctx = await init({
database,
baseURL: "http://localhost:3000",
emailAndPassword: {
enabled: false,
},
plugins: [
{
id: "test-plugin",
init(ctx) {
return {
context: ctx,
options: {
emailAndPassword: {
enabled: true,
},
},
};
},
},
],
});
expect(ctx.options.emailAndPassword?.enabled).toBe(false);
});
});

View File

@@ -55,11 +55,6 @@ export const init = async (options: BetterAuthOptions) => {
baseURL: baseURL ? new URL(baseURL).origin : "",
basePath: options.basePath || "/api/auth",
plugins: plugins.concat(internalPlugins),
emailAndPassword: {
...options.emailAndPassword,
enabled: options.emailAndPassword?.enabled ?? false,
autoSignIn: options.emailAndPassword?.autoSignIn ?? true,
},
};
const cookies = getCookies(options);
const tables = getAuthTables(options);