feat: add superadmin management
This commit is contained in:
@@ -19,6 +19,7 @@ type UserRow = {
|
||||
display_name: string;
|
||||
role: AuthUser['role'];
|
||||
password_hash: string;
|
||||
is_active: boolean;
|
||||
};
|
||||
|
||||
const serializeUser = (user: UserRow): AuthUser => ({
|
||||
@@ -37,7 +38,7 @@ export const authRoutes: FastifyPluginAsync = async (app) => {
|
||||
const result = await pool.query<UserRow>(
|
||||
`insert into users (email, password_hash, display_name)
|
||||
values ($1, $2, $3)
|
||||
returning id, email, display_name, role, password_hash`,
|
||||
returning id, email, display_name, role, password_hash, is_active`,
|
||||
[input.email, passwordHash, input.name],
|
||||
);
|
||||
const user = serializeUser(result.rows[0]);
|
||||
@@ -54,12 +55,12 @@ export const authRoutes: FastifyPluginAsync = async (app) => {
|
||||
app.post('/login', async (request, reply) => {
|
||||
const input = credentialsSchema.parse(request.body);
|
||||
const result = await pool.query<UserRow>(
|
||||
`select id, email, display_name, role, password_hash from users where email = $1`,
|
||||
`select id, email, display_name, role, password_hash, is_active from users where email = $1`,
|
||||
[input.email],
|
||||
);
|
||||
const account = result.rows[0];
|
||||
|
||||
if (!account || !(await verifyPassword(input.password, account.password_hash))) {
|
||||
if (!account || !account.is_active || !(await verifyPassword(input.password, account.password_hash))) {
|
||||
return reply.code(401).send({ error: 'Invalid email or password' });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user