mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
fix auth tests
This commit is contained in:
@@ -39,7 +39,10 @@ describe("AppAuth", () => {
|
|||||||
test("creates user on register", async () => {
|
test("creates user on register", async () => {
|
||||||
const auth = new AppAuth(
|
const auth = new AppAuth(
|
||||||
{
|
{
|
||||||
enabled: true
|
enabled: true,
|
||||||
|
jwt: {
|
||||||
|
secret: "123456"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
ctx
|
ctx
|
||||||
);
|
);
|
||||||
@@ -57,6 +60,9 @@ describe("AppAuth", () => {
|
|||||||
disableConsoleLog();
|
disableConsoleLog();
|
||||||
const res = await app.request("/password/register", {
|
const res = await app.request("/password/register", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email: "some@body.com",
|
email: "some@body.com",
|
||||||
password: "123456"
|
password: "123456"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from "core/utils";
|
} from "core/utils";
|
||||||
import type { Context, Hono } from "hono";
|
import type { Context, Hono } from "hono";
|
||||||
import { deleteCookie, getSignedCookie, setSignedCookie } from "hono/cookie";
|
import { deleteCookie, getSignedCookie, setSignedCookie } from "hono/cookie";
|
||||||
import { decode, sign, verify } from "hono/jwt";
|
import { sign, verify } from "hono/jwt";
|
||||||
import type { CookieOptions } from "hono/utils/cookie";
|
import type { CookieOptions } from "hono/utils/cookie";
|
||||||
import { omit } from "lodash-es";
|
import { omit } from "lodash-es";
|
||||||
|
|
||||||
@@ -177,7 +177,12 @@ export class Authenticator<Strategies extends Record<string, Strategy> = Record<
|
|||||||
payload.exp = Math.floor(Date.now() / 1000) + this.config.jwt.expires;
|
payload.exp = Math.floor(Date.now() / 1000) + this.config.jwt.expires;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sign(payload, this.config.jwt?.secret ?? "", this.config.jwt?.alg ?? "HS256");
|
const secret = this.config.jwt.secret;
|
||||||
|
if (!secret || secret.length === 0) {
|
||||||
|
throw new Error("Cannot sign JWT without a secret");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sign(payload, secret, this.config.jwt?.alg ?? "HS256");
|
||||||
}
|
}
|
||||||
|
|
||||||
async verify(jwt: string): Promise<boolean> {
|
async verify(jwt: string): Promise<boolean> {
|
||||||
|
|||||||
Reference in New Issue
Block a user