mirror of
https://github.com/kyantech/Palmr.git
synced 2025-11-04 14:03:33 +00:00
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:
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user