Files
waseel/lib/users.ts
T
Krikorios a0b297285a 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
2026-08-23 16:38:41 +03:00

40 lines
795 B
TypeScript

import { sql } from "@/lib/db";
import { signJwt } from "@/lib/jwt";
export type UserProfile = {
id: string;
name: string;
email: string;
role: string | null;
};
type UserRow = {
id: string;
name: string;
email: string;
role: string | null;
};
export const toProfile = (row: UserRow): UserProfile => ({
id: row.id,
name: row.name,
email: row.email,
role: row.role,
});
export const issueSession = (
row: UserRow,
): { token: string; user: UserProfile } => ({
token: signJwt({ sub: row.id, email: row.email }),
user: toProfile(row),
});
export const findUserByEmail = async (
email: string,
): Promise<UserRow | null> => {
const rows = await sql<UserRow>`
SELECT id, name, email, role FROM users WHERE email = ${email}
`;
return rows[0] ?? null;
};