Ejemplo n.º 1
0
async def get_current_user(
    request: Request,
    authorization: AuthJWT = Depends(),
    Authorization: str = Header(None),
    userService: UserService = Depends(),
):
    """ Get current user by jwt token provided """
    try:
        current_username = authorization.get_jwt_subject()
        authorization.jwt_required()

        current_user = await userService.get_user(username=current_username)

        return UserSerializer.from_orm(current_user)
    except JWTDecodeError:
        return JSONResponse(
            {
                "status": "Error",
                "info": "Invalid or expired token",
            },
            status_code=400,
        )