mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-16 03:40:23 +08:00

* Use a generic Protocol model for User instead of Pydantic
* Remove UserDB Pydantic schema
* Harmonize schema variable naming to avoid confusions
* Revamp OAuth account model management
* Revamp AccessToken DB strategy to adopt generic model approach
* Make ID a generic instead of forcing UUIDs
* Improve generic typing
* Improve Strategy typing
* Tweak base DB typing
* Don't set Pydantic schemas on FastAPIUsers class: pass it directly on router creation
* Add IntegerIdMixin and export related classes
* Start to revamp doc for V10
* Revamp OAuth documentation
* Fix code highlights
* Write the 9.x.x ➡️ 10.x.x migration doc
* Fix pyproject.toml
25 lines
597 B
Python
25 lines
597 B
Python
from typing import List
|
|
|
|
import motor.motor_asyncio
|
|
from beanie import PydanticObjectId
|
|
from fastapi_users.db import BaseOAuthAccount, BeanieBaseUser, BeanieUserDatabase
|
|
from pydantic import Field
|
|
|
|
DATABASE_URL = "mongodb://localhost:27017"
|
|
client = motor.motor_asyncio.AsyncIOMotorClient(
|
|
DATABASE_URL, uuidRepresentation="standard"
|
|
)
|
|
db = client["database_name"]
|
|
|
|
|
|
class OAuthAccount(BaseOAuthAccount):
|
|
pass
|
|
|
|
|
|
class User(BeanieBaseUser[PydanticObjectId]):
|
|
oauth_accounts: List[OAuthAccount] = Field(default_factory=list)
|
|
|
|
|
|
async def get_user_db():
|
|
yield BeanieUserDatabase(User)
|