Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import * as decode from 'jwt-decode'; const get = require('lodash/get'); export const isAuthorized = (req: Request, groups?: string[]): void => { const token = get(req, 'headers.authorization', ''); if (token) { const userDetails = decode(token) as any; if (groups) { const res = groups.filter(n => userDetails['cognito:groups'].includes(n)); if (!res.length) { throw new Error('Nemáte dostatečná oprávnění pro provedení této akce.'); } } return; } throw new Error('Nepřihlášený uživatel.'); }; |