feat(auth): enhance trusted device management for 2FA

- Added lastUsedAt timestamp to the TrustedDevice model for tracking device usage.
- Implemented new endpoints for retrieving and removing trusted devices.
- Updated AuthService to manage trusted devices, including methods for getting and removing devices.
- Enhanced the user interface to support trusted device management, including modals for removing devices.
- Added translations for new messages related to trusted devices in multiple languages.
This commit is contained in:
Daniel Luiz Alves
2025-07-09 23:43:57 -03:00
parent ad689bd6d9
commit f3f792e053
32 changed files with 5892 additions and 3444 deletions

View File

@@ -122,4 +122,47 @@ export class AuthController {
return reply.status(400).send({ error: error.message });
}
}
async getTrustedDevices(request: FastifyRequest, reply: FastifyReply) {
try {
const userId = (request as any).user?.userId;
if (!userId) {
return reply.status(401).send({ error: "Unauthorized: a valid token is required to access this resource." });
}
const devices = await this.authService.getTrustedDevices(userId);
return reply.send({ devices });
} catch (error: any) {
return reply.status(400).send({ error: error.message });
}
}
async removeTrustedDevice(request: FastifyRequest, reply: FastifyReply) {
try {
const userId = (request as any).user?.userId;
if (!userId) {
return reply.status(401).send({ error: "Unauthorized: a valid token is required to access this resource." });
}
const { id } = request.params as { id: string };
await this.authService.removeTrustedDevice(userId, id);
return reply.send({ success: true, message: "Trusted device removed successfully" });
} catch (error: any) {
return reply.status(400).send({ error: error.message });
}
}
async removeAllTrustedDevices(request: FastifyRequest, reply: FastifyReply) {
try {
const userId = (request as any).user?.userId;
if (!userId) {
return reply.status(401).send({ error: "Unauthorized: a valid token is required to access this resource." });
}
const result = await this.authService.removeAllTrustedDevices(userId);
return reply.send(result);
} catch (error: any) {
return reply.status(400).send({ error: error.message });
}
}
}