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" }