forked from Significant-Gravitas/AutoGPT
-
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.
fix(builder,server) Add missing create user calls (Significant-Gravit…
…as#7784) * fix missing create user calls * formating and linting
- Loading branch information
1 parent
5b9caa4
commit f0ab795
Showing
4 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
from typing import Optional | ||
|
||
from fastapi import HTTPException | ||
from prisma.models import User | ||
|
||
from autogpt_server.data.db import prisma | ||
|
||
DEFAULT_USER_ID = "3e53486c-cf57-477e-ba2a-cb02dc828e1a" | ||
DEFAULT_EMAIL = "[email protected]" | ||
|
||
|
||
async def get_or_create_user(user_data: dict) -> User: | ||
user = await prisma.user.find_unique(where={"id": user_data["sub"]}) | ||
|
||
user_id = user_data.get("sub") | ||
if not user_id: | ||
raise HTTPException(status_code=401, detail="User ID not found in token") | ||
|
||
user_email = user_data.get("email") | ||
if not user_email: | ||
raise HTTPException(status_code=401, detail="Email not found in token") | ||
|
||
user = await prisma.user.find_unique(where={"id": user_id}) | ||
if not user: | ||
user = await prisma.user.create( | ||
data={ | ||
"id": user_data["sub"], | ||
"email": user_data["email"], | ||
"id": user_id, | ||
"email": user_email, | ||
"name": user_data.get("user_metadata", {}).get("name"), | ||
} | ||
) | ||
|