Skip to content

Commit

Permalink
fix: auth cookies (#202)
Browse files Browse the repository at this point in the history
- Cookie 还是不对
  • Loading branch information
RaoHai authored Aug 16, 2024
2 parents 3b189cc + 492aeac commit 25f20b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/app/services/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import axios from 'axios';
// Get the public bot profile by id
export async function getUserInfo({ clientId }: { clientId?: string }) {
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN;
const response = await axios.get(`${apiDomain}/api/auth/userinfo?clientId=${clientId}`);
const response = await axios.get(`${apiDomain}/api/auth/userinfo?clientId=${clientId}`, { withCredentials: true });
return response.data.data;
}
10 changes: 7 additions & 3 deletions server/routers/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import APIRouter,Cookie, Request, HTTPException, status, Response
from typing import Annotated
from fastapi import APIRouter, Cookie, Request, HTTPException, status, Response

from fastapi.responses import RedirectResponse
import httpx
Expand Down Expand Up @@ -72,12 +73,15 @@ async def callback(request: Request, response: Response):
data = await getUserInfoByToken(token)
supabase = get_client()
supabase.table("profiles").upsert(data).execute()
print(f"auth_callback: {data}")
response = RedirectResponse(url=f'{WEB_URL}', status_code=302)
response.set_cookie(key="petercat_user_token", value=token, httponly=True, secure=True, samesite='Lax')

return RedirectResponse(url=f'{WEB_URL}', status_code=302)
return response

@router.get("/userinfo")
async def userinfo(request: Request, response: Response, petercat_user_token: str = Cookie(None)):
async def userinfo(request: Request, response: Response, petercat_user_token: Annotated[str | None, Cookie()] = None):
print(f"petercat_user_token: {petercat_user_token}")
if not petercat_user_token:
return await getAnonymousUser(request, response)
data = await getAnonymousUserInfoByToken(petercat_user_token) if petercat_user_token.startswith("client|") else await getUserInfoByToken(petercat_user_token)
Expand Down

0 comments on commit 25f20b5

Please sign in to comment.