@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
from sqlalchemy.orm import Session
|
||||
from app.database import get_db
|
||||
@@ -41,28 +41,6 @@ async def get_current_user(
|
||||
is_active=user.is_active
|
||||
)
|
||||
|
||||
async def get_current_user_ws(token: str = Query(...), db: Session = Depends(get_db)) -> CurrentUser:
|
||||
"""The WebSocket authentication helper"""
|
||||
payload = decode_token(token)
|
||||
if not payload:
|
||||
raise AuthenticationError("Invalid token")
|
||||
|
||||
user_id = payload.get("sub")
|
||||
if not user_id:
|
||||
raise AuthenticationError("Invalid token payload")
|
||||
|
||||
user = auth_service.get_user_by_id(db, int(user_id))
|
||||
if not user or not user.is_active:
|
||||
raise AuthenticationError("User not found or inactive")
|
||||
|
||||
return CurrentUser(
|
||||
id=user.id,
|
||||
username=user.username,
|
||||
email=user.email,
|
||||
role=user.role,
|
||||
is_active=user.is_active
|
||||
)
|
||||
|
||||
@router.post("/register", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
|
||||
async def register(user_data: UserRegister, db: Session = Depends(get_db)):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user