Skip to content

Commit

Permalink
remove: permissions - não utilizado
Browse files Browse the repository at this point in the history
  • Loading branch information
agleicesousa committed Dec 17, 2024
1 parent 524e48b commit aa19cbe
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 24 deletions.
1 change: 0 additions & 1 deletion @types/express/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ declare global {
id: number;
email: string;
tipoConta: string;
permissions: string[];
};
}
}
Expand Down
15 changes: 1 addition & 14 deletions src/middlewares/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,11 @@ export async function authMiddleware(
req.user = {
id: decoded.id,
email: decoded.email,
tipoConta: decoded.tipoConta,
permissions: decoded.permissions
tipoConta: decoded.tipoConta
};
next();
} catch (error) {
console.error('Erro ao verificar token:', error);
return res.status(403).json({ error: 'Token inválido ou expirado.' });
}
}

export function permissoes(necessaria: string) {
return (req: Request, res: Response, next: NextFunction) => {
const usuario = req.user;
if (usuario?.permissions?.includes(necessaria)) {
return next();
}
return res.status(403).json({
error: 'Acesso negado. Permissão insuficiente.'
});
};
}
1 change: 1 addition & 0 deletions src/routes/pdiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ pdiRouter.get('/professor/turmas/:id/alunos', (req, res) =>
);

pdiRouter.delete('/:id', (req, res) => pdiController.deletarPDI(req, res));

export default pdiRouter;
10 changes: 1 addition & 9 deletions src/utils/jwtUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,16 @@ export interface JwtPayload {
id: number;
email: string;
tipoConta: string;
permissions: string[];
iat?: number;
exp?: number;
}

const permissoesPorFuncao: Record<string, string[]> = {
admin: ['MANAGE_USERS', 'MANAGE_TURMAS'],
professor: ['VIEW_OWN_TURMAS', 'VIEW_ALUNOS_IN_OWN_TURMAS'],
aluno: ['VIEW_OWN_PDI']
};

export function gerarToken(payload: {
id: number;
email: string;
tipoConta: string;
}): string {
const permissions = permissoesPorFuncao[payload.tipoConta] || [];
return jwt.sign({ ...payload, permissions }, SECRET_KEY, { expiresIn: '1d' });
return jwt.sign({ ...payload }, SECRET_KEY, { expiresIn: '1d' });
}

export function verificarToken(token: string): JwtPayload {
Expand Down

0 comments on commit aa19cbe

Please sign in to comment.