Add self-hosted auth, admin API, and owner web dashboard
- Replace Clerk with self-hosted JWT auth (register/login/verify, bcrypt passwords, Gmail OTP with console fallback) - Add lib/db.ts pg pool + transaction helpers; seed script migrates legacy Clerk-era schema (drop clerk_id, enforce UUID ids and unique email) - Add owner-gated admin API: stats, users, drivers CRUD, rides - Add dashboard/ Vite React owner dashboard (login, overview, users, fleet, rides) with dev-server proxy to avoid Expo CORS middleware - Add scripts/set-owner.mjs for role management
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { randomBytes, scryptSync, timingSafeEqual } from "crypto";
|
||||
|
||||
const KEY_LENGTH = 64;
|
||||
|
||||
export const hashPassword = (password: string): string => {
|
||||
const salt = randomBytes(16).toString("hex");
|
||||
const hash = scryptSync(password, salt, KEY_LENGTH).toString("hex");
|
||||
return `scrypt:${salt}:${hash}`;
|
||||
};
|
||||
|
||||
export const verifyPassword = (
|
||||
password: string,
|
||||
stored: string,
|
||||
): boolean => {
|
||||
const [scheme, salt, hash] = stored.split(":");
|
||||
if (scheme !== "scrypt" || !salt || !hash) return false;
|
||||
|
||||
const candidate = scryptSync(password, salt, KEY_LENGTH);
|
||||
const expected = Buffer.from(hash, "hex");
|
||||
|
||||
return (
|
||||
candidate.length === expected.length && timingSafeEqual(candidate, expected)
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user