(token: str = Depends(oauth2_scheme))
| 19 | |
| 20 | # Define the dependency function to get the current user |
| 21 | async def get_current_user(token: str = Depends(oauth2_scheme)) -> User: |
| 22 | credentials_exception = HTTPException( |
| 23 | status_code=status.HTTP_401_UNAUTHORIZED, |
| 24 | detail="Could not validate credentials", |
| 25 | headers={"WWW-Authenticate": "Bearer"}, |
| 26 | ) |
| 27 | try: |
| 28 | payload = jwt.decode(token, AppConfig.SECRET_KEY, algorithms=[AppConfig.ALGORITHM]) |
| 29 | username: str = payload.get("sub") |
| 30 | if username is None: |
| 31 | raise credentials_exception |
| 32 | # Here you should get the user from your Neo4j database using the username |
| 33 | # and convert it to the UserInDB model. |
| 34 | |
| 35 | user = get_user_from_db(username) |
| 36 | if user is None: |
| 37 | raise credentials_exception |
| 38 | except JWTError: |
| 39 | raise credentials_exception |
| 40 | return user |
| 41 | |
| 42 | # Helper function to convert Neo4j datetime to Python datetime |
| 43 | def neo4j_datetime_to_python_datetime(neo4j_dt_str: str) -> datetime: |
nothing calls this directly
no test coverage detected