-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Eccoar/165_login_user
Solve #165 - Autenticação de usuário
- Loading branch information
Showing
6 changed files
with
296 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { paths } from '../../config/enviroments'; | ||
import { UsersProxy } from '../users/UsersProxy'; | ||
|
||
const userProxy = new UsersProxy(paths.configUsers()); | ||
|
||
export default class AuthValidator { | ||
checkJWT = async ( | ||
req: Request, | ||
resp: Response, | ||
next: NextFunction, | ||
): Promise<Response | void> => { | ||
const token: string = req.headers['authorization']; | ||
if (!token) | ||
return resp | ||
.status(401) | ||
.json({ status: 'error', message: 'Access Denied' }); | ||
try { | ||
await userProxy.authorization(token); | ||
} catch (err) { | ||
return resp | ||
.status(403) | ||
.json({ status: 'error', message: 'Access Denied' }); | ||
} | ||
next(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.