Buuntu / fastapi-react

🚀 Cookiecutter Template for FastAPI + React Projects. Using PostgreSQL, SQLAlchemy, and Docker
MIT License
2.22k stars 349 forks source link

Duplicate Superuser with same email #172

Open harkaranbrar7 opened 3 years ago

harkaranbrar7 commented 3 years ago

from app.db.session import get_db
from app.db.crud import create_user, get_user_by_email
from app.db.schemas import UserCreate
from app.db.session import SessionLocal

def init() -> None:
    db = SessionLocal()
    user = get_user_by_email(db, email="{{cookiecutter.superuser_email}}")

    if not user:
        create_user(
            db,
            UserCreate(
                email="{{cookiecutter.superuser_email}}",
                password="{{cookiecutter.superuser_password}}",
                is_active=True,
                is_superuser=True,
            ),
        )