Update verify.py (#1200)

* Update verify.py

When using a schema setup as proposed in the documentation like: ReadUser, CreateUser, UpdateUser and BaseUser in the combination with MongoDB / Beanie, the verify() method will not "enforce" the `user_schema` but instead will return the `BaseUser` which will cause serialisation errors as such:

```
pydantic.error_wrappers.ValidationError: 1 validation error for ReadUser
response -> id
```
because the mapping between MongoDBs internal `_id` and the Pydantic `id` does not work.

* use `from_orm`
This commit is contained in:
0xJan
2023-04-29 10:21:01 +02:00
committed by GitHub
parent 867d78f818
commit 8959a12d56

View File

@ -69,7 +69,8 @@ def get_verify_router(
user_manager: BaseUserManager[models.UP, models.ID] = Depends(get_user_manager),
):
try:
return await user_manager.verify(token, request)
user = await user_manager.verify(token, request)
return user_schema.from_orm(user)
except (exceptions.InvalidVerifyToken, exceptions.UserNotExists):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,