mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix 500 error in get_messages route
This commit is contained in:
+9
-10
@@ -7,10 +7,18 @@ from db import SessionLocal
|
|||||||
from app import security
|
from app import security
|
||||||
|
|
||||||
|
|
||||||
|
# Зависимость для получения сессии БД
|
||||||
|
def get_db():
|
||||||
|
db = SessionLocal()
|
||||||
|
try:
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
# Зависимость для получения текущего пользователя
|
# Зависимость для получения текущего пользователя
|
||||||
def get_current_user(
|
def get_current_user(
|
||||||
credentials: HTTPAuthorizationCredentials = Depends(security),
|
credentials: HTTPAuthorizationCredentials = Depends(security),
|
||||||
db: Session = Depends(lambda: SessionLocal())
|
db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
token = credentials.credentials
|
token = credentials.credentials
|
||||||
payload = verify_token(token)
|
payload = verify_token(token)
|
||||||
@@ -28,12 +36,3 @@ def get_current_user(
|
|||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
)
|
)
|
||||||
return {"user_id": user.id, "username": user.username}
|
return {"user_id": user.id, "username": user.username}
|
||||||
|
|
||||||
|
|
||||||
# Зависимость для получения сессии БД
|
|
||||||
def get_db():
|
|
||||||
db = SessionLocal()
|
|
||||||
try:
|
|
||||||
yield db
|
|
||||||
finally:
|
|
||||||
db.close()
|
|
||||||
@@ -50,6 +50,7 @@ def register(request: RegisterRequest, db: Session = Depends(get_db)):
|
|||||||
password = request.password.strip()
|
password = request.password.strip()
|
||||||
confirm_password = request.confirm_password.strip()
|
confirm_password = request.confirm_password.strip()
|
||||||
|
|
||||||
|
# Validate input
|
||||||
if not is_valid_username(username):
|
if not is_valid_username(username):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
|||||||
Reference in New Issue
Block a user