added onBeforeUpdate listener + auto create a secret on auth enable

This commit is contained in:
dswbx
2024-11-21 16:24:33 +01:00
parent 2fe924b65c
commit 6077f0e64f
12 changed files with 158 additions and 67 deletions

View File

@@ -19,10 +19,23 @@ describe("AppAuth", () => {
await auth.build();
const config = auth.toJSON();
expect(config.jwt.secret).toBeUndefined();
expect(config.jwt).toBeUndefined();
expect(config.strategies.password.config).toBeUndefined();
});
test("enabling auth: generate secret", async () => {
const auth = new AppAuth(undefined, ctx);
await auth.build();
const oldConfig = auth.toJSON(true);
//console.log(oldConfig);
await auth.schema().patch("enabled", true);
await auth.build();
const newConfig = auth.toJSON(true);
//console.log(newConfig);
expect(newConfig.jwt.secret).not.toBe(oldConfig.jwt.secret);
});
test("creates user on register", async () => {
const auth = new AppAuth(
{