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:
@@ -0,0 +1,23 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { Algorithm, hashRawSync } from '@node-rs/argon2';
|
||||
|
||||
/** Node < 24 无 crypto.argon2Sync,Memind 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,
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user