Add argon2 polyfill and unified preview/API startup for admin login.

Node < 24 lacks crypto.argon2Sync; wire @node-rs/argon2 fallback and start Admin API alongside vite preview in local and remote deploy flows.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
John
2026-06-17 16:38:58 -07:00
parent 9ecfa73831
commit 7a5b9cc912
7 changed files with 414 additions and 21 deletions
+23
View File
@@ -0,0 +1,23 @@
import crypto from 'node:crypto';
import { Algorithm, hashRawSync } from '@node-rs/argon2';
/** Node < 24 无 crypto.argon2SyncMemind user-auth 登录会崩溃。 */
export function ensureArgon2Sync() {
if (typeof crypto.argon2Sync === 'function') return;
crypto.argon2Sync = (algorithm, options = {}) => {
if (algorithm !== 'argon2id') {
throw new Error(`unsupported argon2 algorithm: ${algorithm}`);
}
const message = options.message ?? '';
const nonce = options.nonce ?? Buffer.alloc(0);
return hashRawSync(String(message), {
algorithm: Algorithm.Argon2id,
salt: nonce,
parallelism: options.parallelism ?? 1,
outputLen: options.tagLength ?? 32,
memoryCost: options.memory ?? 65536,
timeCost: options.passes ?? 3,
});
};
}