From c07623feee67c4905708aa7b388e17d28bba3c39 Mon Sep 17 00:00:00 2001 From: achandrabalan Date: Sun, 21 Apr 2024 18:31:05 -0400 Subject: [PATCH 1/5] init --- backend/python/app/rest/auth_routes.py | 1 + docker-compose.yml | 36 ++++++++++++------------ frontend/src/APIClients/AuthAPIClient.ts | 3 +- frontend/src/APIClients/BaseAPIClient.ts | 5 ++++ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/backend/python/app/rest/auth_routes.py b/backend/python/app/rest/auth_routes.py index 77061d5..93e6e77 100644 --- a/backend/python/app/rest/auth_routes.py +++ b/backend/python/app/rest/auth_routes.py @@ -31,6 +31,7 @@ "httponly": True, "samesite": ("None" if os.getenv("PREVIEW_DEPLOY") else "Strict"), "secure": (os.getenv("FLASK_CONFIG") == "production"), + "max_age": 60 * 60 * 24 * 7, # 1 week } diff --git a/docker-compose.yml b/docker-compose.yml index a31aff5..f67b13f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,24 +34,24 @@ services: condition: service_healthy env_file: - ./.env - py-backend: - # TODO: rename container for your project - container_name: scv2_py_backend - restart: always - build: - context: ./backend/python - dockerfile: Dockerfile - ports: - - 8080:8080 - dns: - - 8.8.8.8 - volumes: - - ./backend/python:/app - depends_on: - db: - condition: service_healthy - env_file: - - ./.env + # py-backend: + # # TODO: rename container for your project + # container_name: scv2_py_backend + # restart: always + # build: + # context: ./backend/python + # dockerfile: Dockerfile + # ports: + # - 8080:8080 + # dns: + # - 8.8.8.8 + # volumes: + # - ./backend/python:/app + # depends_on: + # db: + # condition: service_healthy + # env_file: + # - ./.env db: # TODO: rename container for your project container_name: scv2_db diff --git a/frontend/src/APIClients/AuthAPIClient.ts b/frontend/src/APIClients/AuthAPIClient.ts index 4f784e5..695564d 100644 --- a/frontend/src/APIClients/AuthAPIClient.ts +++ b/frontend/src/APIClients/AuthAPIClient.ts @@ -134,7 +134,7 @@ type LogoutFunction = ( FetchResult< { logout: null; - }, + }, Record, Record > @@ -143,6 +143,7 @@ type LogoutFunction = ( const logout = async ( authenticatedUserId: string, logoutFunction: LogoutFunction, + options?: { raiseError?: boolean} ): Promise => { let success = false; try { diff --git a/frontend/src/APIClients/BaseAPIClient.ts b/frontend/src/APIClients/BaseAPIClient.ts index f14fe95..7f026e1 100644 --- a/frontend/src/APIClients/BaseAPIClient.ts +++ b/frontend/src/APIClients/BaseAPIClient.ts @@ -42,6 +42,7 @@ baseAPIClient.interceptors.request.use(async (config: AxiosRequestConfig) => { (typeof decodedToken === "string" || decodedToken.exp <= Math.round(new Date().getTime() / 1000)) ) { + try { const { data } = await axios.post( `${process.env.REACT_APP_BACKEND_URL}/auth/refresh`, {}, @@ -56,6 +57,10 @@ baseAPIClient.interceptors.request.use(async (config: AxiosRequestConfig) => { ); newConfig.headers.Authorization = `Bearer ${accessToken}`; + } catch (error) { + localStorage.removeItem(AUTHENTICATED_USER_KEY); + window.location.href = "/login"; + } } } From f6fb384d4d39874401ae611ffffb033dc59240f3 Mon Sep 17 00:00:00 2001 From: achandrabalan Date: Sun, 21 Apr 2024 19:28:27 -0400 Subject: [PATCH 2/5] uncomment compose file --- docker-compose.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f67b13f..a31aff5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,24 +34,24 @@ services: condition: service_healthy env_file: - ./.env - # py-backend: - # # TODO: rename container for your project - # container_name: scv2_py_backend - # restart: always - # build: - # context: ./backend/python - # dockerfile: Dockerfile - # ports: - # - 8080:8080 - # dns: - # - 8.8.8.8 - # volumes: - # - ./backend/python:/app - # depends_on: - # db: - # condition: service_healthy - # env_file: - # - ./.env + py-backend: + # TODO: rename container for your project + container_name: scv2_py_backend + restart: always + build: + context: ./backend/python + dockerfile: Dockerfile + ports: + - 8080:8080 + dns: + - 8.8.8.8 + volumes: + - ./backend/python:/app + depends_on: + db: + condition: service_healthy + env_file: + - ./.env db: # TODO: rename container for your project container_name: scv2_db From 00f187e5a9a4982510ea7b4fcca19e7bc2c87146 Mon Sep 17 00:00:00 2001 From: achandrabalan Date: Sun, 21 Apr 2024 19:39:06 -0400 Subject: [PATCH 3/5] remove invalid token from local storage on refresh fail / graphql --- frontend/src/index.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index a11d6a2..4053527 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -49,6 +49,7 @@ const authLink = setContext(async (_, { headers }) => { (typeof decodedToken === "string" || decodedToken.exp <= Math.round(new Date().getTime() / 1000)) ) { + try { const { data } = await axios.post( `${process.env.REACT_APP_BACKEND_URL}/graphql`, { query: REFRESH_MUTATION }, @@ -62,6 +63,10 @@ const authLink = setContext(async (_, { headers }) => { accessToken, ); token = accessToken; + } catch { + localStorage.removeItem(AUTHENTICATED_USER_KEY); + location.reload(); + } } } // return the headers to the context so httpLink can read them From e0285dcce452a988207ad48434ccd2cf739e6919 Mon Sep 17 00:00:00 2001 From: achandrabalan Date: Sun, 21 Apr 2024 19:41:20 -0400 Subject: [PATCH 4/5] clean up --- backend/python/app/rest/auth_routes.py | 2 +- frontend/src/APIClients/AuthAPIClient.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/python/app/rest/auth_routes.py b/backend/python/app/rest/auth_routes.py index 93e6e77..54c5c7a 100644 --- a/backend/python/app/rest/auth_routes.py +++ b/backend/python/app/rest/auth_routes.py @@ -31,7 +31,7 @@ "httponly": True, "samesite": ("None" if os.getenv("PREVIEW_DEPLOY") else "Strict"), "secure": (os.getenv("FLASK_CONFIG") == "production"), - "max_age": 60 * 60 * 24 * 7, # 1 week + "max_age": 60 * 60 * 24 , # 1 day } diff --git a/frontend/src/APIClients/AuthAPIClient.ts b/frontend/src/APIClients/AuthAPIClient.ts index 695564d..5069cf2 100644 --- a/frontend/src/APIClients/AuthAPIClient.ts +++ b/frontend/src/APIClients/AuthAPIClient.ts @@ -143,7 +143,6 @@ type LogoutFunction = ( const logout = async ( authenticatedUserId: string, logoutFunction: LogoutFunction, - options?: { raiseError?: boolean} ): Promise => { let success = false; try { From 80c2d322fd6b062be9bcc1551b5c5e8530345b5b Mon Sep 17 00:00:00 2001 From: Aathithan Chandrabalan Date: Mon, 29 Apr 2024 04:34:31 +0900 Subject: [PATCH 5/5] reload syntax error --- frontend/src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 4053527..a0aa7f6 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -65,7 +65,7 @@ const authLink = setContext(async (_, { headers }) => { token = accessToken; } catch { localStorage.removeItem(AUTHENTICATED_USER_KEY); - location.reload(); + window.location.reload(); } } }