From 076f82b93329f531cbfc4d7051444f2de59a4f47 Mon Sep 17 00:00:00 2001 From: dswbx Date: Wed, 23 Jul 2025 08:44:08 +0200 Subject: [PATCH] update custom auth strategy test --- app/__test__/auth/strategies/custom.test.ts | 28 +++++++++++++++------ app/src/index.ts | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/__test__/auth/strategies/custom.test.ts b/app/__test__/auth/strategies/custom.test.ts index e5f7f702..cc5ecb81 100644 --- a/app/__test__/auth/strategies/custom.test.ts +++ b/app/__test__/auth/strategies/custom.test.ts @@ -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 { constructor(config: Partial = {}) { 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); + } }); } } diff --git a/app/src/index.ts b/app/src/index.ts index 27061743..d0471da7 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -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";