From d16638ffd09a7314304c7f325bee706a7b49dfd1 Mon Sep 17 00:00:00 2001 From: Zikriya Date: Mon, 2 Sep 2024 18:12:20 +0500 Subject: [PATCH] multiswapAuth added --- app/lib/multiswapAuth.ts | 31 +++++++++++++++++++++++++++++++ config/config.json | 10 +++++----- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100755 app/lib/multiswapAuth.ts diff --git a/app/lib/multiswapAuth.ts b/app/lib/multiswapAuth.ts new file mode 100755 index 0000000..679b809 --- /dev/null +++ b/app/lib/multiswapAuth.ts @@ -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); + } + }; +}; diff --git a/config/config.json b/config/config.json index 87fb2c8..a5d0c5c 100755 --- a/config/config.json +++ b/config/config.json @@ -42,23 +42,23 @@ "authenticationCommunityMemberV1": { "enabled": true, "priority": 100, - "route": "/api/v1/community-member((?!$))((?!/users/forgot-password))((?!/users/reset-password))((?!/users/sign-in))((?!/users/sign-up))((?!/users/test))*", + "route": "/api/v1/community-member((?!$))((?!/multiSwap))((?!/users/forgot-password))((?!/users/reset-password))((?!/users/sign-in))((?!/users/sign-up))((?!/users/test))*", "module": { "name": "path:./app/lib/auth" } }, - "authenticationCommunityMemberV2": { + "authenticationMultiswapCommunityMember": { "enabled": true, "priority": 100, - "route": "/api/v2/community-member((?!$))*", + "route": "/api/v1/community-member/multiSwap((?!$))*", "module": { - "name": "path:./app/lib/auth" + "name": "path:./app/lib/multiswapAuth" } }, "authenticationApplicationUser": { "enabled": true, "priority": 100, - "route": "/api/v1/application-user((?!$))((?!/token))*", + "route": "/api/v1/application-user((?!$))((?!/token))((?!/addresses))*", "module": { "name": "path:./app/lib/auth" }