mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-10 04:19:32 +00:00
fix: allow plugins to set email and password values (#1212)
This commit is contained in:
@@ -100,10 +100,6 @@ exports[`init > should match config 1`] = `
|
|||||||
"open": true,
|
"open": true,
|
||||||
"readonly": false,
|
"readonly": false,
|
||||||
},
|
},
|
||||||
"emailAndPassword": {
|
|
||||||
"autoSignIn": true,
|
|
||||||
"enabled": false,
|
|
||||||
},
|
|
||||||
"plugins": [],
|
"plugins": [],
|
||||||
"secret": "better-auth-secret-123456789",
|
"secret": "better-auth-secret-123456789",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export const signUpEmail = <O extends BetterAuthOptions>() =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!ctx.context.options.emailAndPassword.autoSignIn ||
|
ctx.context.options.emailAndPassword.autoSignIn === false ||
|
||||||
ctx.context.options.emailAndPassword.requireEmailVerification
|
ctx.context.options.emailAndPassword.requireEmailVerification
|
||||||
) {
|
) {
|
||||||
return ctx.json({
|
return ctx.json({
|
||||||
|
|||||||
@@ -98,4 +98,53 @@ describe("init", async () => {
|
|||||||
ok: true,
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ export const init = async (options: BetterAuthOptions) => {
|
|||||||
baseURL: baseURL ? new URL(baseURL).origin : "",
|
baseURL: baseURL ? new URL(baseURL).origin : "",
|
||||||
basePath: options.basePath || "/api/auth",
|
basePath: options.basePath || "/api/auth",
|
||||||
plugins: plugins.concat(internalPlugins),
|
plugins: plugins.concat(internalPlugins),
|
||||||
emailAndPassword: {
|
|
||||||
...options.emailAndPassword,
|
|
||||||
enabled: options.emailAndPassword?.enabled ?? false,
|
|
||||||
autoSignIn: options.emailAndPassword?.autoSignIn ?? true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
const cookies = getCookies(options);
|
const cookies = getCookies(options);
|
||||||
const tables = getAuthTables(options);
|
const tables = getAuthTables(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user