-
Notifications
You must be signed in to change notification settings - Fork 7
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 #434 from zikriya/feature/decentralization
multiswapAuth added
- Loading branch information
Showing
2 changed files
with
36 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
decodeToken, | ||
getUser, | ||
invalidRequest, | ||
Response, | ||
} from "../helpers/authHelpers/rootAuthHelper"; | ||
const AUTHORIZATION_MISSING = "Authorization header missing"; | ||
|
||
module.exports = function () { | ||
return async function (req: any, res: any, next: any) { | ||
if (!req.headers.authorization) { | ||
return res.http401(AUTHORIZATION_MISSING); | ||
} | ||
|
||
try { | ||
let response: Response = decodeToken(req); | ||
if (!response?.isValid) { | ||
return invalidRequest(res); | ||
} | ||
const user = await getUser(response.id, response?.role); | ||
if (!user) { | ||
return invalidRequest(res); | ||
} | ||
req.user = user; | ||
next(); | ||
} catch (error) { | ||
console.log(error); | ||
return invalidRequest(res); | ||
} | ||
}; | ||
}; |
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