We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When trying to get current user I'm getting the error
File ".\main.py", line 788, in tester current_user = Depends(FastAPIUsers.current_user()) AttributeError: type object 'FastAPIUsers' has no attribute 'current_user'
The code is:
from fastapi_users import FastAPIUsers current_user = Depends(FastAPIUsers.current_user())
I expected to get the current user that sent the request to my FastAPI in any format that is readable
I built the API with FastAPI and I'm trying to find out which is the user that sent the request to me
The text was updated successfully, but these errors were encountered:
@LidorPrototype hi,
In the documentation it's saying:
FastAPI Users provides a dependency callable to easily inject authenticated user in your routes. They are available from your FastAPIUsers instance.
So you need to instantiate a FastAPIUsers object and derive current_users from this. Like this:
from fastapi_users import FastAPIUsers ... fastapi_users = FastAPIUsers[User, PydanticObjectId](get_user_manager, [auth_backend]) current_active_user = fastapi_users.current_user(active=True)
after you can use this variable like this:
async def get_database_meta(database_id: PydanticObjectId, user: User = Depends(current_active_user)): return await DatabaseMetadata.find_one(DatabaseMetadata.user == user.id, DatabaseMetadata.id == database_id)
I believe that the examples in the documentation are confusing for users because the variable fastapi_users has the same name as the package.
fastapi_users
Sorry, something went wrong.
No branches or pull requests
Describe the bug
When trying to get current user I'm getting the error
The code is:
Expected behavior
I expected to get the current user that sent the request to my FastAPI in any format that is readable
Configuration
Additional context
I built the API with FastAPI and I'm trying to find out which is the user that sent the request to me
The text was updated successfully, but these errors were encountered: