Skip to content

Commit

Permalink
Merge pull request #418 from marzmehr/CSOCA-460
Browse files Browse the repository at this point in the history
adding Auth-refresh
  • Loading branch information
marzmehr authored Apr 13, 2023
2 parents 7b1e892 + 43af604 commit 126fd6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@mdi/font": "^7.1.96",
"@types/underscore": "^1.10.0",
"axios": "^0.27.2",
"axios-auth-refresh": "^3.3.6",
"bootstrap": "^4.6.2",
"bootstrap-vue": "^2.22.0",
"core-js": "^3.24.1",
Expand Down
20 changes: 20 additions & 0 deletions web/src/plugins/http.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import axios from "axios";
import { AxiosError } from 'axios'
import Vue from 'vue'
import createAuthRefreshInterceptor, {AxiosAuthRefreshOptions} from 'axios-auth-refresh';

const options: AxiosAuthRefreshOptions = {
statusCodes: [ 401, 403]
}


const refreshAuthLogic = failedRequest => axios.get('/user-info/').then(response => {

location.replace(response.data.login_uri);
return Promise.resolve();

}).catch((error: AxiosError) => {
console.error(error);
});




const httpInstance = configureInstance();

function configureInstance(){
createAuthRefreshInterceptor(axios, refreshAuthLogic, options);
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
axios.defaults.xsrfCookieName = "csrftoken";
axios.defaults.baseURL = `${process.env.BASE_URL}api/v1`;
Expand Down

0 comments on commit 126fd6c

Please sign in to comment.