Skip to content

Commit

Permalink
fix: user token cookies key (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai authored Jun 3, 2024
2 parents 961c3d9 + bf6a6e8 commit d2d0d81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/auth/get_user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def generateAnonymousUser(clientId: str):
"sid": secrets.token_urlsafe(32)
}

return clientId, data
return token, data

async def getAnonymousUserInfoByToken(token: str):
supabase = get_client()
Expand Down
11 changes: 5 additions & 6 deletions server/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ async def getAnonymousUser(request: Request, response: Response):

supabase = get_client()
supabase.table("profiles").upsert(data).execute()
response.set_cookie(key="petercat", value=token, httponly=True, secure=True, samesite='Lax')
response.set_cookie(key="user_id", value=data['id'], httponly=True, secure=True, samesite='Lax')
response.set_cookie(key="petercat_user_token", value=token, httponly=True, secure=True, samesite='Lax')
return { "data": data, "status": 200}

@router.get("/login")
Expand All @@ -74,14 +73,14 @@ async def callback(request: Request, response: Response):
supabase = get_client()
supabase.table("profiles").upsert(data).execute()
response = RedirectResponse(url=f'{WEB_URL}', status_code=302)
response.set_cookie(key="petercat", value=token, httponly=True, secure=True, samesite='Lax')
response.set_cookie(key="petercat_user_token", value=token, httponly=True, secure=True, samesite='Lax')
return response

@router.get("/userinfo")
async def userinfo(request: Request, response: Response, petercat: str = Cookie(None)):
if not petercat:
async def userinfo(request: Request, response: Response, petercat_user_token: str = Cookie(None)):
if not petercat_user_token:
return await getAnonymousUser(request, response)
data = await getAnonymousUserInfoByToken(petercat) if petercat.startswith("client|") else await getUserInfoByToken(petercat)
data = await getAnonymousUserInfoByToken(petercat_user_token) if petercat_user_token.startswith("client|") else await getUserInfoByToken(user_token)
if data is None:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Failed to get access token")
if data :
Expand Down

0 comments on commit d2d0d81

Please sign in to comment.