-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from jqueja/57-signup-and-log-in-backend-and-f…
…ront-end 57 signup and log in backend and front end
- Loading branch information
Showing
15 changed files
with
238 additions
and
38 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from fastapi import APIRouter, Request, HTTPException, status | ||
from sqlalchemy import create_engine, text | ||
import sqlalchemy | ||
from src import database as db | ||
from dotenv import load_dotenv | ||
from fastapi.responses import JSONResponse | ||
from uuid import UUID | ||
|
||
load_dotenv() | ||
|
||
import os | ||
from supabase import create_client | ||
from pydantic import BaseModel | ||
|
||
|
||
url = os.environ.get("SUPABASE_URL") | ||
key = os.environ.get("SUPABASE_KEY") | ||
supabase = create_client(url, key) | ||
|
||
router = APIRouter( | ||
prefix="/login", | ||
tags=["login"], | ||
) | ||
|
||
class LogUserRequest(BaseModel): | ||
user_email: str | ||
user_password: str | ||
|
||
|
||
@router.post("") | ||
def login_user(request: LogUserRequest): | ||
|
||
try: | ||
response = supabase.auth.sign_in_with_password({ "email": request.user_email, "password": request.user_password }) | ||
|
||
|
||
user_id = response.user.id | ||
|
||
# Return the user_id in the response | ||
return JSONResponse(content={"user_id": user_id}, status_code=200) | ||
|
||
except Exception as e: | ||
# Check if the error is due to invalid credentials | ||
if "Invalid login credentials" in str(e): | ||
raise HTTPException(status_code=401, detail="Invalid credentials") | ||
else: | ||
# Handle other AuthApiError cases as needed | ||
raise HTTPException(status_code=500, detail="Internal server error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters