Skip to content

Commit

Permalink
Merge pull request #434 from zikriya/feature/decentralization
Browse files Browse the repository at this point in the history
multiswapAuth added
  • Loading branch information
zikriya authored Sep 2, 2024
2 parents b80ff4e + d16638f commit 151f179
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
31 changes: 31 additions & 0 deletions app/lib/multiswapAuth.ts
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);
}
};
};
10 changes: 5 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 151f179

Please sign in to comment.