Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cli/templates/features/auth/files/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import crypto from "node:crypto";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep auth template runtime-agnostic

Replacing the Web Crypto global with import crypto from "node:crypto" makes the generated lib/auth.ts module Node-specific, so projects running this template in non-Node runtimes (edge/worker-style deployments) will fail to load the module before login/signup handlers execute. This is a behavioral regression from the previous implementation, which only required crypto.subtle and stayed portable across runtimes.

Useful? React with 👍 / 👎.


export async function hashPassword(password: string): Promise<string> {
const msgBuffer = new TextEncoder().encode(password);
const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
Expand All @@ -8,5 +10,7 @@ export async function hashPassword(password: string): Promise<string> {

export async function verifyPassword(password: string, hash: string): Promise<boolean> {
const computedHash = await hashPassword(password);
return computedHash === hash;
const actual = crypto.createHash('sha256').update(computedHash).digest();
const expected = crypto.createHash('sha256').update(hash).digest();
return crypto.timingSafeEqual(actual, expected);
}
5 changes: 4 additions & 1 deletion src/transforms/esm/bundle-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @module transforms/esm/bundle-recovery
*/

import crypto from "node:crypto";
import { createFileSystem, exists } from "#veryfront/platform/compat/fs.ts";
import { join } from "#veryfront/compat/path/index.ts";
import { rendererLogger } from "#veryfront/utils";
Expand Down Expand Up @@ -80,7 +81,9 @@ export async function recoverHttpBundleByHash(
let m: RegExpExecArray | null;
while ((m = BUNDLE_RE.exec(cachedCode)) !== null) {
const tHash = m[2]!;
if (tHash === hash) continue;
const actual = crypto.createHash('sha256').update(tHash).digest();
const expected = crypto.createHash('sha256').update(hash).digest();
if (crypto.timingSafeEqual(actual, expected)) continue;
transitiveDeps.push({
path: join(absoluteCacheDir, `http-${tHash}.mjs`),
hash: tHash,
Expand Down
Loading