mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 08:06:00 +00:00
update custom auth strategy test
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user