mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-04 00:56:01 +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 { describe, it, expect } from "bun:test";
|
||||||
import { createApp } from "core/test/utils";
|
import { createApp } from "core/test/utils";
|
||||||
import { s } from "bknd/utils";
|
import { s } from "bknd/utils";
|
||||||
@@ -13,21 +13,33 @@ class CustomStrategy extends AuthStrategy<typeof customStrategySchema> {
|
|||||||
constructor(config: Partial<CustomStrategyOptions> = {}) {
|
constructor(config: Partial<CustomStrategyOptions> = {}) {
|
||||||
super(config as any, "custom", "custom", "form");
|
super(config as any, "custom", "custom", "form");
|
||||||
}
|
}
|
||||||
|
|
||||||
getSchema() {
|
getSchema() {
|
||||||
return customStrategySchema;
|
return customStrategySchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
getController() {
|
getController(authenticator: Authenticator) {
|
||||||
return new Hono()
|
return new Hono()
|
||||||
.post("/login", async (c) => {
|
.post("/login", async (c) => {
|
||||||
return c.json({
|
try {
|
||||||
message: "Hello, world!",
|
// 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) => {
|
.post("/register", async (c) => {
|
||||||
return c.json({
|
try {
|
||||||
message: "Hello, world!",
|
// 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,
|
UserPool,
|
||||||
AuthAction,
|
AuthAction,
|
||||||
AuthUserResolver,
|
AuthUserResolver,
|
||||||
|
Authenticator,
|
||||||
} from "auth/authenticate/Authenticator";
|
} from "auth/authenticate/Authenticator";
|
||||||
export { AuthStrategy } from "auth/authenticate/strategies/Strategy";
|
export { AuthStrategy } from "auth/authenticate/strategies/Strategy";
|
||||||
export * as AuthPermissions from "auth/auth-permissions";
|
export * as AuthPermissions from "auth/auth-permissions";
|
||||||
|
|||||||
Reference in New Issue
Block a user