update custom auth strategy test

This commit is contained in:
dswbx
2025-07-23 08:44:08 +02:00
parent 324e872849
commit 076f82b933
2 changed files with 21 additions and 8 deletions
+20 -8
View File
@@ -1,4 +1,4 @@
import { AuthStrategy, registries } from "bknd";
import { AuthStrategy, registries, type Authenticator } from "bknd";
import { describe, it, expect } from "bun:test";
import { createApp } from "core/test/utils";
import { s } from "bknd/utils";
@@ -13,21 +13,33 @@ class CustomStrategy extends AuthStrategy<typeof customStrategySchema> {
constructor(config: Partial<CustomStrategyOptions> = {}) {
super(config as any, "custom", "custom", "form");
}
getSchema() {
return customStrategySchema;
}
getController() {
getController(authenticator: Authenticator) {
return new Hono()
.post("/login", async (c) => {
return c.json({
message: "Hello, world!",
});
try {
// do magic, and it succeeds, resolve login
// @ts-ignore
return await authenticator.resolveLogin();
} catch (e) {
// in case of error, respond with the error
return authenticator.respondWithError(c, e as any);
}
})
.post("/register", async (c) => {
return c.json({
message: "Hello, world!",
});
try {
// do magic, and it succeeds, resolve register
// @ts-ignore
return await authenticator.resolveRegister();
} catch (e) {
// in case of error, respond with the error
return authenticator.respondWithError(c, e as any);
}
});
}
}
+1
View File
@@ -69,6 +69,7 @@ export type {
UserPool,
AuthAction,
AuthUserResolver,
Authenticator,
} from "auth/authenticate/Authenticator";
export { AuthStrategy } from "auth/authenticate/strategies/Strategy";
export * as AuthPermissions from "auth/auth-permissions";