user profile 401 Unauthorized #1327
-
Describe the bugThe user registration and login were successfully, but the requests for current user profile /users/me return 401 Unauthorized. I could not figure out why?
Configuration
FastAPI Users configuration
Additional context
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I tested and didn't encounter this issue. Could you provide F12 -> Network -> Headers and Preview information? |
Beta Was this translation helpful? Give feedback.
-
Thanks. Both postman and axios js got the same issue. It seems that the issue comes from the authentication and the get_users_router has not been called during the request. Do I have to use a redis or db to store the token? I need help. response headers: |
Beta Was this translation helpful? Give feedback.
-
No need for Redis or a database to store the token. If you create a minimal example repo, I can take a look for you. |
Beta Was this translation helpful? Give feedback.
-
You defined your model with an class Users(SQLModelBaseUserDB, table=True):
__tablename__ = "user"
__table_args__ = {'extend_existing': True}
id: Optional[int] = Field(default=None, primary_key=True, nullable=False, title="ID") However, you used the class UserManager(UUIDIDMixin, BaseUserManager[User, id]): You need to be consistent on the ID type. If you wish to keep an integer ID, class UserManager(IntegerIDMixin, BaseUserManager[User, int]): Ref: https://fastapi-users.github.io/fastapi-users/12.1/configuration/user-manager/#the-id-parser-mixin |
Beta Was this translation helpful? Give feedback.
You defined your model with an
int
ID:However, you used the
UUIDIDMixin
in the user manager:You need to be consistent on the ID type. If you wish to keep an integer ID,
UserManager
should look like this:Ref: https://fastapi-users.github.io/fastapi-users/12.1/configuration/user-manager/#the-id-parser-mixin