mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-11-03 05:27:06 +08:00
Fix SQLAlchemy examples
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from fastapi import Depends, FastAPI
|
||||
|
||||
from app.db import create_db_and_tables
|
||||
from app.models import UserDB
|
||||
from app.users import (
|
||||
auth_backend,
|
||||
@ -35,3 +36,9 @@ app.include_router(
|
||||
@app.get("/authenticated-route")
|
||||
async def authenticated_route(user: UserDB = Depends(current_active_user)):
|
||||
return {"message": f"Hello {user.email}!"}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def on_startup():
|
||||
# Not needed if you setup a migration system like Alembic
|
||||
await create_db_and_tables()
|
||||
|
||||
@ -17,7 +17,7 @@ Base: DeclarativeMeta = declarative_base()
|
||||
|
||||
|
||||
class UserTable(Base, SQLAlchemyBaseUserTable):
|
||||
oauth_accounts = relationship("OAuthAccount")
|
||||
oauth_accounts = relationship("OAuthAccountTable")
|
||||
|
||||
|
||||
class OAuthAccountTable(SQLAlchemyBaseOAuthAccountTable, Base):
|
||||
|
||||
@ -18,8 +18,8 @@ SECRET = "SECRET"
|
||||
|
||||
|
||||
google_oauth_client = GoogleOAuth2(
|
||||
os.environ["GOOGLE_OAUTH_CLIENT_ID"],
|
||||
os.environ["GOOGLE_OAUTH_CLIENT_SECRET"],
|
||||
os.getenv("GOOGLE_OAUTH_CLIENT_ID", ""),
|
||||
os.getenv("GOOGLE_OAUTH_CLIENT_SECRET", ""),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import uvicorn
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("app.app:app", host="0.0.0.0", port=5000, log_level="info")
|
||||
uvicorn.run("app.app:app", host="0.0.0.0", log_level="info")
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
fastapi
|
||||
fastapi-users[sqlalchemy,oauth]
|
||||
fastapi-users[sqlalchemy2,oauth]
|
||||
uvicorn[standard]
|
||||
aiosqlite
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
from fastapi import Depends, FastAPI
|
||||
|
||||
from app.db import create_db_and_tables
|
||||
from app.models import UserDB
|
||||
from app.users import auth_backend, current_active_user, fastapi_users
|
||||
|
||||
@ -25,3 +26,9 @@ app.include_router(fastapi_users.get_users_router(), prefix="/users", tags=["use
|
||||
@app.get("/authenticated-route")
|
||||
async def authenticated_route(user: UserDB = Depends(current_active_user)):
|
||||
return {"message": f"Hello {user.email}!"}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def on_startup():
|
||||
# Not needed if you setup a migration system like Alembic
|
||||
await create_db_and_tables()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import uvicorn
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("app.app:app", host="0.0.0.0", port=5000, log_level="info")
|
||||
uvicorn.run("app.app:app", host="0.0.0.0", log_level="info")
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
fastapi
|
||||
fastapi-users[sqlalchemy]
|
||||
fastapi-users[sqlalchemy2]
|
||||
uvicorn[standard]
|
||||
aiosqlite
|
||||
|
||||
Reference in New Issue
Block a user