Last active
October 4, 2022 05:49
-
-
Save AliMilani/baf55d4037c8580e25967fa520b264e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| swaggerOptions: { | |
| persistAuthorization: true, | |
| responseInterceptor: function (response) { | |
| if (!response.url.includes("auth/signin")) return response; | |
| const accessToken = response.headers["x-access-token"]; | |
| console.log(response, accessToken); | |
| if (!accessToken) return response; | |
| let oldAuth = JSON.parse(localStorage.getItem("authorized")); | |
| if (oldAuth && oldAuth.accessToken) { | |
| oldAuth.accessToken.value = accessToken; | |
| localStorage.setItem("authorized", JSON.stringify(oldAuth)); | |
| } else { | |
| const newAuth = { | |
| accessToken: { | |
| name: "accessToken", | |
| schema: { | |
| type: "apiKey", | |
| description: | |
| "you can get this token from /auth/login endpoint at the response header", | |
| name: "x-access-token", | |
| in: "header", | |
| }, | |
| value: `${accessToken}`, | |
| }, | |
| }; | |
| localStorage.setItem("authorized", JSON.stringify(newAuth)); | |
| } | |
| ui.authActions.authorize({ | |
| accessToken: { | |
| name: "accessToken", | |
| schema: { | |
| type: "apiKey", | |
| in: "header", | |
| name: "x-access-token", | |
| description: | |
| "you can get this token from /auth/login endpoint at the response header", | |
| }, | |
| value: accessToken, | |
| }, | |
| }); | |
| return response; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment