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:
Krikorios
2026-08-23 16:38:41 +03:00
parent fbe92c9d16
commit a0b297285a
75 changed files with 5158 additions and 2837 deletions
+44
View File
@@ -0,0 +1,44 @@
// Promotes (or demotes) a user's role. Usage:
// node scripts/set-owner.mjs owner@example.com owner
// node scripts/set-owner.mjs owner@example.com rider
import pg from "pg";
import { readFileSync } from "fs";
const [email, role = "owner"] = process.argv.slice(2);
if (!email) {
console.error("Usage: node scripts/set-owner.mjs <email> [role]");
console.error("Roles: owner | driver | rider");
process.exit(1);
}
const env = readFileSync(new URL("../.env", import.meta.url), "utf8");
const databaseUrl = env
.split("\n")
.find((l) => l.startsWith("DATABASE_URL="))
?.split("=")
.slice(1)
.join("=")
.trim()
.replace(/^"|"$/g, "");
const pool = new pg.Pool({ connectionString: databaseUrl });
try {
const { rows } = await pool.query(
`UPDATE users SET email_verified = TRUE, role = $2 WHERE email = $1 RETURNING id, email, role`,
[email.toLowerCase(), role],
);
if (!rows[0]) {
console.error(`No user found with email ${email}`);
process.exit(1);
}
console.log(
`Updated ${rows[0].email}: role=${rows[0].role}, email_verified=true`,
);
} finally {
await pool.end();
}