Skip to content

how to debug the endpoints created by fastapi_users.get_users_router #1271

Answered by frankie567
lpdswing asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the optional flag in this case:

current_optional_user = fastapi_users.current_user(optional=True)

async def set_global_user(request: Request, user = Depends(current_optional_user)):
    # request.state is really useful to put shared state in the request object
    # Ref: https://www.starlette.io/requests/#other-state
    if user is not None:
        request.state.global_user_id = user.id

app = FastAPI(dependencies=[Depends(set_global_user)])

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lpdswing
Comment options

@frankie567
Comment options

Answer selected by lpdswing
@lpdswing
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants