mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Only create KhojUser on login if doesn't already exist
This commit is contained in:
parent
3d8d6145f2
commit
f8e5e118e1
1 changed files with 7 additions and 4 deletions
|
@ -75,13 +75,16 @@ async def delete_khoj_token(user: KhojUser, token: str):
|
|||
async def get_or_create_user(token: dict) -> KhojUser:
|
||||
user = await get_user_by_token(token)
|
||||
if not user:
|
||||
user = await create_google_user(token)
|
||||
user = await create_user_by_token(token)
|
||||
return user
|
||||
|
||||
|
||||
async def create_google_user(token: dict) -> KhojUser:
|
||||
user = await KhojUser.objects.acreate(username=token.get("email"), email=token.get("email"))
|
||||
await user.asave()
|
||||
async def create_user_by_token(token: dict) -> KhojUser:
|
||||
user = await KhojUser.objects.filter(email=token.get("email")).aget_or_none()
|
||||
if not user:
|
||||
user = await KhojUser.objects.acreate(username=token.get("email"), email=token.get("email"))
|
||||
await user.asave()
|
||||
|
||||
await GoogleUser.objects.acreate(
|
||||
sub=token.get("sub"),
|
||||
azp=token.get("azp"),
|
||||
|
|
Loading…
Reference in a new issue