bump 0.19.0, update readme with use cases, small fixes

- fix password strategy openapi tags
- fix cli run picking up memory if specified
- fix view transition chrome crash
This commit is contained in:
dswbx
2025-10-31 11:55:27 +01:00
parent 6093f4f46f
commit 5417aa174e
5 changed files with 86 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
import type { User } from "bknd";
import type { Authenticator } from "auth/authenticate/Authenticator";
import { InvalidCredentialsException } from "auth/errors";
import { hash, $console, s, parse, jsc } from "bknd/utils";
import { hash, $console, s, parse, jsc, describeRoute } from "bknd/utils";
import { Hono } from "hono";
import { compare as bcryptCompare, genSalt as bcryptGenSalt, hash as bcryptHash } from "bcryptjs";
import { AuthStrategy } from "./Strategy";
@@ -84,51 +84,67 @@ export class PasswordStrategy extends AuthStrategy<typeof schema> {
});
const payloadSchema = this.getPayloadSchema();
hono.post("/login", jsc("query", redirectQuerySchema), async (c) => {
try {
const body = parse(payloadSchema, await authenticator.getBody(c), {
onError: (errors) => {
$console.error("Invalid login payload", [...errors]);
throw new InvalidCredentialsException();
},
});
const { redirect } = c.req.valid("query");
return await authenticator.resolveLogin(c, this, body, this.verify(body.password), {
redirect,
});
} catch (e) {
return authenticator.respondWithError(c, e as any);
}
});
hono.post("/register", jsc("query", redirectQuerySchema), async (c) => {
try {
const { redirect } = c.req.valid("query");
const { password, email, ...body } = parse(
payloadSchema,
await authenticator.getBody(c),
{
hono.post(
"/login",
describeRoute({
summary: "Login with email and password",
tags: ["auth"],
}),
jsc("query", redirectQuerySchema),
async (c) => {
try {
const body = parse(payloadSchema, await authenticator.getBody(c), {
onError: (errors) => {
$console.error("Invalid register payload", [...errors]);
new InvalidCredentialsException();
$console.error("Invalid login payload", [...errors]);
throw new InvalidCredentialsException();
},
},
);
});
const { redirect } = c.req.valid("query");
const profile = {
...body,
email,
strategy_value: await this.hash(password),
};
return await authenticator.resolveLogin(c, this, body, this.verify(body.password), {
redirect,
});
} catch (e) {
return authenticator.respondWithError(c, e as any);
}
},
);
return await authenticator.resolveRegister(c, this, profile, async () => void 0, {
redirect,
});
} catch (e) {
return authenticator.respondWithError(c, e as any);
}
});
hono.post(
"/register",
describeRoute({
summary: "Register a new user with email and password",
tags: ["auth"],
}),
jsc("query", redirectQuerySchema),
async (c) => {
try {
const { redirect } = c.req.valid("query");
const { password, email, ...body } = parse(
payloadSchema,
await authenticator.getBody(c),
{
onError: (errors) => {
$console.error("Invalid register payload", [...errors]);
new InvalidCredentialsException();
},
},
);
const profile = {
...body,
email,
strategy_value: await this.hash(password),
};
return await authenticator.resolveRegister(c, this, profile, async () => void 0, {
redirect,
});
} catch (e) {
return authenticator.respondWithError(c, e as any);
}
},
);
return hono;
}

View File

@@ -110,7 +110,10 @@ export async function makeAppFromEnv(options: Partial<RunOptions> = {}) {
// try to use an in-memory connection
} else if (options.memory) {
console.info("Using", c.cyan("in-memory"), "connection");
app = await makeApp({ server: { platform: options.server } });
app = await makeApp({
server: { platform: options.server },
connection: { url: ":memory:" },
});
// finally try to use env variables
} else {

View File

@@ -123,11 +123,14 @@ export function BkndProvider({
fetching.current = Fetching.None;
};
if ("startViewTransition" in document) {
// disable view transitions for now
// because it causes browser crash on heavy pages (e.g. schema)
commit();
/* if ("startViewTransition" in document) {
document.startViewTransition(commit);
} else {
commit();
}
} */
});
}