diff --git a/backend/api/auth/auth.py b/backend/api/auth/auth.py index 53daa0af..f773bea0 100644 --- a/backend/api/auth/auth.py +++ b/backend/api/auth/auth.py @@ -2,8 +2,9 @@ from ..settings import Settings -from fastapi import Depends +from fastapi import Depends, HTTPException from fastapi_jwt_auth import AuthJWT +from fastapi_jwt_auth.exceptions import JWTDecodeError from passlib import pwd from passlib.context import CryptContext @@ -31,4 +32,10 @@ def auth_check(Authorize): if settings.DISABLE_AUTH == "True": return else: - return Authorize.jwt_required() + try: + return Authorize.jwt_required() + except JWTDecodeError as exc: + status_code = exc.status_code + if exc.message == "Signature verification failed": + status_code = 401 + raise HTTPException(status_code=status_code, detail=exc.message) diff --git a/backend/api/routers/compose.py b/backend/api/routers/compose.py index fb2df33a..4f5d6b77 100644 --- a/backend/api/routers/compose.py +++ b/backend/api/routers/compose.py @@ -27,7 +27,7 @@ def get_project(project_name, Authorize: AuthJWT = Depends()): return get_compose(project_name) -@router.get("/{project_name}/{action}") +@router.get("/{project_name}/actions/{action}") def get_compose_action(project_name, action, Authorize: AuthJWT = Depends()): auth_check(Authorize) if action == "delete": @@ -42,7 +42,7 @@ def write_compose_project( auth_check(Authorize) return write_compose(compose=compose) -@router.get("/{project_name}/{action}/{app}") +@router.get("/{project_name}/actions/{action}/{app}") def get_compose_app_action(project_name, action, app, Authorize: AuthJWT = Depends()): auth_check(Authorize) return compose_app_action(project_name, action, app) diff --git a/frontend/src/main.js b/frontend/src/main.js index ccbb48b2..91c5af11 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -20,7 +20,7 @@ function createAxiosResponseInterceptor() { const interceptor = axios.interceptors.response.use( response => response, error => { - if (error.response.status !== 401 || error.response.status !== 403) { + if (error.response.status !== 401) { return Promise.reject(error); } @@ -35,7 +35,7 @@ function createAxiosResponseInterceptor() { return axios(error.response.config); }) .catch(error => { - if (error.response.status !== 401 || error.response.status !== 403) { + if (error.response.status !== 401) { return Promise.reject(error); } else { store.dispatch("auth/AUTH_LOGOUT"); diff --git a/frontend/src/store/modules/projects.js b/frontend/src/store/modules/projects.js index f3c4fe1d..ffc41b31 100644 --- a/frontend/src/store/modules/projects.js +++ b/frontend/src/store/modules/projects.js @@ -111,7 +111,7 @@ const actions = { }, ProjectAction({ commit, dispatch }, { Name, Action }) { commit("setLoading", true); - const url = `/api/compose/${Name}/${Action}`; + const url = `/api/compose/actions/${Name}/${Action}`; axios .get(url) .then(response => { @@ -128,7 +128,7 @@ const actions = { }, ProjectAppAction({ commit, dispatch }, { Project, Name, Action }) { commit("setLoading", true); - const url = `/api/compose/${Project}/${Action}/${Name}`; + const url = `/api/compose/${Project}/actions/${Action}/${Name}`; axios .get(url) .then(response => {