🐛 Catch invalid user refresh
This commit is contained in:
parent
8c2cf01f40
commit
22ca522615
1 changed files with 6 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ from fastapi import APIRouter, Body, Depends, Header, HTTPException, Request, st
|
|||
from fastapi.security import OAuth2, OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
from fastapi.security.utils import get_authorization_scheme_param
|
||||
from pydantic import BaseModel
|
||||
from tortoise.exceptions import DoesNotExist
|
||||
|
||||
from ohmyapi.builtin.auth.models import Group, User
|
||||
|
||||
|
|
@ -214,7 +215,11 @@ async def refresh_token(refresh_token: TokenRefresh = Body(...)):
|
|||
)
|
||||
|
||||
user_id = payload.get("sub")
|
||||
user = await User.get(id=user_id)
|
||||
try:
|
||||
user = await User.get(id=user_id)
|
||||
except DoesNotExist:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
if not user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="User not found"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue