mirror of
				https://github.com/fastapi-users/fastapi-users.git
				synced 2025-10-31 17:38:30 +08:00 
			
		
		
		
	 72aa68c462
			
		
	
	72aa68c462
	
	
	
		
			
			* 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
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from beanie import init_beanie
 | |
| from fastapi import Depends, FastAPI
 | |
| 
 | |
| from app.db import User, db
 | |
| from app.schemas import UserCreate, UserRead, UserUpdate
 | |
| from app.users import auth_backend, current_active_user, fastapi_users
 | |
| 
 | |
| app = FastAPI()
 | |
| 
 | |
| app.include_router(
 | |
|     fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"]
 | |
| )
 | |
| app.include_router(
 | |
|     fastapi_users.get_register_router(UserRead, UserCreate),
 | |
|     prefix="/auth",
 | |
|     tags=["auth"],
 | |
| )
 | |
| app.include_router(
 | |
|     fastapi_users.get_reset_password_router(),
 | |
|     prefix="/auth",
 | |
|     tags=["auth"],
 | |
| )
 | |
| app.include_router(
 | |
|     fastapi_users.get_verify_router(UserRead),
 | |
|     prefix="/auth",
 | |
|     tags=["auth"],
 | |
| )
 | |
| app.include_router(
 | |
|     fastapi_users.get_users_router(UserRead, UserUpdate),
 | |
|     prefix="/users",
 | |
|     tags=["users"],
 | |
| )
 | |
| 
 | |
| 
 | |
| @app.get("/authenticated-route")
 | |
| async def authenticated_route(user: User = Depends(current_active_user)):
 | |
|     return {"message": f"Hello {user.email}!"}
 | |
| 
 | |
| 
 | |
| @app.on_event("startup")
 | |
| async def on_startup():
 | |
|     await init_beanie(
 | |
|         database=db,
 | |
|         document_models=[
 | |
|             User,
 | |
|         ],
 | |
|     )
 |