Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(platform): Enable auth on local-backend mode by default (#8405)

Zamil Majdy27c9ec5bcdad
diff --git a/autogpt_platform/backend/.env.example b/autogpt_platform/backend/.env.example
index 0cb4d7abd7..0ec84ca83e 100644
--- a/autogpt_platform/backend/.env.example
+++ b/autogpt_platform/backend/.env.example
@@ -20,13 +20,13 @@ PYRO_HOST=localhost
SENTRY_DSN=
## User auth with Supabase is required for any of the 3rd party integrations with auth to work.
-ENABLE_AUTH=false
+ENABLE_AUTH=true
SUPABASE_URL=http://localhost:8000
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q
SUPABASE_JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-long
# For local development, you may need to set FRONTEND_BASE_URL for the OAuth flow for integrations to work.
-# FRONTEND_BASE_URL=http://localhost:3000
+FRONTEND_BASE_URL=http://localhost:3000
## == INTEGRATION CREDENTIALS == ##
# Each set of server side credentials is required for the corresponding 3rd party
diff --git a/autogpt_platform/backend/README.md b/autogpt_platform/backend/README.md
index 00194b304e..ab91027df2 100644
--- a/autogpt_platform/backend/README.md
+++ b/autogpt_platform/backend/README.md
@@ -58,7 +58,7 @@ We use the Poetry to manage the dependencies. To set up the project, follow thes
6. Migrate the database. Be careful because this deletes current data in the database.
```sh
- docker compose up db redis -d
+ docker compose up db -d
poetry run prisma migrate deploy
```
@@ -66,9 +66,10 @@ We use the Poetry to manage the dependencies. To set up the project, follow thes
### Starting the server without Docker
-Run the following command to build the dockerfiles:
+Run the following command to run database in docker but the application locally:
```sh
+docker compose --profile local up deps --build --detach
poetry run app
```
diff --git a/autogpt_platform/backend/backend/data/user.py b/autogpt_platform/backend/backend/data/user.py
index 6c8696379e..477b3bae65 100644
--- a/autogpt_platform/backend/backend/data/user.py
+++ b/autogpt_platform/backend/backend/data/user.py
@@ -37,19 +37,17 @@ async def get_user_by_id(user_id: str) -> Optional[User]:
return User.model_validate(user) if user else None
-async def create_default_user(enable_auth: str) -> Optional[User]:
- if not enable_auth.lower() == "true":
- user = await prisma.user.find_unique(where={"id": DEFAULT_USER_ID})
- if not user:
- user = await prisma.user.create(
- data={
- "id": DEFAULT_USER_ID,
- "email": "[email protected]",
- "name": "Default User",
- }
- )
- return User.model_validate(user)
- return None
+async def create_default_user() -> Optional[User]:
+ user = await prisma.user.find_unique(where={"id": DEFAULT_USER_ID})
+ if not user:
+ user = await prisma.user.create(
+ data={
+ "id": DEFAULT_USER_ID,
+ "email": "[email protected]",
+ "name": "Default User",
+ }
+ )
+ return User.model_validate(user)
async def get_user_metadata(user_id: str) -> UserMetadataRaw:
diff --git a/autogpt_platform/backend/backend/server/ws_api.py b/autogpt_platform/backend/backend/server/ws_api.py
index 5e35693be4..8cbda22e1e 100644
--- a/autogpt_platform/backend/backend/server/ws_api.py
+++ b/autogpt_platform/backend/backend/server/ws_api.py
@@ -28,7 +28,7 @@ async def lifespan(app: FastAPI):
docs_url = "/docs" if settings.config.app_env == AppEnvironment.LOCAL else None
-app = FastAPI(lifespan=lifespan)
+app = FastAPI(lifespan=lifespan, docs_url=docs_url)
_connection_manager = None
logger.info(f"CORS allow origins: {settings.config.backend_cors_allow_origins}")
@@ -66,7 +66,7 @@ async def event_broadcaster(manager: ConnectionManager):
async def authenticate_websocket(websocket: WebSocket) -> str:
- if settings.config.enable_auth.lower() == "true":
+ if settings.config.enable_auth:
token = websocket.query_params.get("token")
if not token:
await websocket.close(code=4001, reason="Missing authentication token")
diff --git a/autogpt_platform/backend/backend/util/settings.py b/autogpt_platform/backend/backend/util/settings.py
index 1ac875fdf9..f521bf104f 100644
--- a/autogpt_platform/backend/backend/util/settings.py
+++ b/autogpt_platform/backend/backend/util/settings.py
@@ -69,8 +69,8 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
default="localhost",
description="The default hostname of the Pyro server.",
)
- enable_auth: str = Field(
- default="false",
+ enable_auth: bool = Field(
+ default=True,
description="If authentication is enabled or not",
)
enable_credit: str = Field(
@@ -133,7 +133,7 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
)
frontend_base_url: str = Field(
- default="",
+ default="http://localhost:3000",
description="Can be used to explicitly set the base URL for the frontend. "
"This value is then used to generate redirect URLs for OAuth flows.",
)
diff --git a/autogpt_platform/backend/backend/util/test.py b/autogpt_platform/backend/backend/util/test.py
index 704d6507e0..d1e2d83f7f 100644
--- a/autogpt_platform/backend/backend/util/test.py
+++ b/autogpt_platform/backend/backend/util/test.py
@@ -31,7 +31,7 @@ class SpinTestServer:
await db.connect()
await initialize_blocks()
- await create_default_user("false")
+ await create_default_user()
return self
diff --git a/autogpt_platform/backend/test/__init__.py b/autogpt_platform/backend/test/__init__.py
index e69de29bb2..d10438719d 100644
--- a/autogpt_platform/backend/test/__init__.py
+++ b/autogpt_platform/backend/test/__init__.py
@@ -0,0 +1,3 @@
+import os
+
+os.environ["ENABLE_AUTH"] = "false"
diff --git a/autogpt_platform/docker-compose.yml b/autogpt_platform/docker-compose.yml
index be6f1f49ed..a1ae16b3ea 100644
--- a/autogpt_platform/docker-compose.yml
+++ b/autogpt_platform/docker-compose.yml
@@ -142,3 +142,24 @@ services:
extends:
file: ./supabase/docker/docker-compose.yml
service: vector
+
+ deps:
+ <<: *supabase-services
+ profiles:
+ - local
+ image: busybox
+ command: /bin/true
+ depends_on:
+ - studio
+ - kong
+ - auth
+ - rest
+ - realtime
+ - storage
+ - imgproxy
+ - meta
+ - functions
+ - analytics
+ - db
+ - vector
+ - redis
diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts
index dc80bb0401..60f2a33369 100644
--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts
+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/baseClient.ts
@@ -273,10 +273,10 @@ export default class BaseAutoGPTServerAPI {
if (
response.status === 403 &&
- response.statusText === "Not authenticated" &&
typeof window !== "undefined" // Check if in browser environment
) {
window.location.href = "/login";
+ return null;
}
let errorDetail;