Skip to content

Commit 29a0ef9

Browse files
committed
fixed firebase issues
1 parent 4946745 commit 29a0ef9

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

backend/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ pdm run ruff format .
110110
## Environment Variables
111111
Environment variables are currently stored in an .env file within the base repository (not the backend folder). You will need to copy the local environment variables stored in the following notion [page](https://www.notion.so/uwblueprintexecs/Environment-Variables-11910f3fb1dc80e4bc67d35c3d65d073?pvs=4) to get the database working.
112112

113+
### Firebase Configuration
114+
To set up Firebase authentication:
115+
116+
1. Place your `serviceAccountKey.json` file in the `backend/` directory
117+
- This file should be obtained from your Firebase Console
118+
- Go to Project Settings > Service Accounts > Generate New Private Key
119+
- The file contains sensitive credentials and is automatically gitignored
120+
121+
2. Ensure your `.env` file includes the following Firebase-related variables:
122+
```
123+
FIREBASE_WEB_API_KEY=your_web_api_key
124+
```
125+
You can find these values in your Firebase Console under Project Settings.
126+
127+
Note: Never commit `serviceAccountKey.json` to version control. It's already added to `.gitignore` for security.
113128
114129
## Adding a new model
115130
When adding a new model, make sure to add it to `app/models/__init__.py` so that the migration script can pick it up when autogenerating the new migration.

backend/app/routes/auth.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
33

44
from ..schemas.auth import AuthResponse, LoginRequest, RefreshRequest, Token
5+
from ..schemas.user import UserCreateRequest, UserCreateResponse
56
from ..services.implementations.auth_service import AuthService
6-
from ..utilities.service_utils import get_auth_service
7+
from ..services.implementations.user_service import UserService
8+
from ..utilities.service_utils import get_auth_service, get_user_service
79

810
router = APIRouter(prefix="/auth", tags=["auth"])
911
security = HTTPBearer()
1012

13+
#TODO: ADD RATE LIMITING
14+
@router.post("/register", response_model=UserCreateResponse)
15+
async def register_user(
16+
user: UserCreateRequest, user_service: UserService = Depends(get_user_service)
17+
):
18+
try:
19+
return await user_service.create_user(user)
20+
except HTTPException as http_ex:
21+
raise http_ex
22+
except Exception as e:
23+
raise HTTPException(status_code=500, detail=str(e))
1124

1225
@router.post("/login", response_model=AuthResponse)
1326
async def login(

backend/app/routes/user.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from fastapi import APIRouter, Depends, HTTPException
22

3-
from app.schemas.user import UserCreateRequest, UserCreateResponse
3+
from app.middleware.auth import has_roles
4+
from app.schemas.user import UserCreateRequest, UserCreateResponse, UserRole
45
from app.services.implementations.user_service import UserService
56
from app.utilities.service_utils import get_user_service
67

@@ -13,10 +14,12 @@
1314
# send email verification via auth_service
1415
# allow signup methods other than email (like sign up w Google)??
1516

16-
17+
#admin only manually create user, not sure if this is needed
1718
@router.post("/", response_model=UserCreateResponse)
1819
async def create_user(
19-
user: UserCreateRequest, user_service: UserService = Depends(get_user_service)
20+
user: UserCreateRequest,
21+
user_service: UserService = Depends(get_user_service),
22+
authorized: bool = has_roles([UserRole.ADMIN])
2023
):
2124
try:
2225
return await user_service.create_user(user)

0 commit comments

Comments
 (0)