From 98ea9bf597a559dac319189cc891df77e3584310 Mon Sep 17 00:00:00 2001
From: Leonardo Christino <leomilho@gmail.com>
Date: Sat, 28 Oct 2023 12:56:00 +0200
Subject: [PATCH] fix(auth): ignore auth if localhost is in url

---
 apps/web/.env                                         | 4 ++--
 apps/web/.env.example                                 | 1 -
 libs/shared/lib/data-access/authorization/useAuth.tsx | 7 ++++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/apps/web/.env b/apps/web/.env
index 90475f97a..0c5463cd0 100644
--- a/apps/web/.env
+++ b/apps/web/.env
@@ -1,8 +1,8 @@
+GRAPHPOLARIS_VERSION=dev
 BACKEND_URL=http://localhost
 BACKEND_WSS_URL=ws://localhost:3001/
 STAGING=dev
-SKIP_LOGIN=true
 BACKEND_USER=:3000
 BACKEND_QUERY=:3003
 BACKEND_SCHEMA=:3002
-GRAPHPOLARIS_VERSION=dev
\ No newline at end of file
+GRAPHPOLARIS_VERSION=dev
diff --git a/apps/web/.env.example b/apps/web/.env.example
index 9c4a604ee..976455964 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -2,7 +2,6 @@ GRAPHPOLARIS_VERSION=
 BACKEND_URL=
 BACKEND_WSS_URL=
 STAGING=
-SKIP_LOGIN=
 BACKEND_USER=
 BACKEND_QUERY=
 BACKEND_SCHEMA=
\ No newline at end of file
diff --git a/libs/shared/lib/data-access/authorization/useAuth.tsx b/libs/shared/lib/data-access/authorization/useAuth.tsx
index 2983c0b31..ee33f3caf 100644
--- a/libs/shared/lib/data-access/authorization/useAuth.tsx
+++ b/libs/shared/lib/data-access/authorization/useAuth.tsx
@@ -24,8 +24,8 @@ export const useAuth = () => {
   const auth = useAuthorizationCache();
 
   const handleError = (err: any) => {
-    if (import.meta.env.SKIP_LOGIN) {
-      console.warn('skipping login');
+    if (domain.includes('localhost')) {
+      console.warn('skipping login for localhost');
       dispatch(
         authorized({
           username: 'UserID',
@@ -63,7 +63,8 @@ export const useAuth = () => {
   const fetchAuthenticated = (input: RequestInfo | URL, init?: RequestInit | undefined): Promise<Response> => {
     if (!init) init = fetchSettings;
 
-    if (!import.meta.env.SKIP_LOGIN) {
+    if (!domain.includes('localhost')) {
+      // Production logic
       init.credentials = 'include';
       init.redirect = 'follow';
       init.method = init.method || 'GET';
-- 
GitLab