Skip to content

Commit

Permalink
fix error during registration (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
KuzenkovAG authored Aug 1, 2023
1 parent ccaa5bb commit e500e68
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = postgresql+asyncpg://%(DB_USER)s:%(DB_PASS)s@%(DB_HOST)s:%(DB_PORT)s/%(DB_NAME)s?async_fallback=True
sqlalchemy.url = %(DATABASE_URL)s?async_fallback=True

[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
Expand Down
8 changes: 2 additions & 6 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from src.config import DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER
from src.database import Base
from src.auth.models import AuthUser, UserQuestionnaire, UserSettings # noqa: F401
from src.posts.models import UserLike, Match, Message # noqa: F401
from src.config import DATABASE_URL

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

section = config.config_ini_section
config.set_section_option(section, "DB_HOST", DB_HOST)
config.set_section_option(section, "DB_PORT", DB_PORT)
config.set_section_option(section, "DB_NAME", DB_NAME)
config.set_section_option(section, "DB_USER", DB_USER)
config.set_section_option(section, "DB_PASS", DB_PASS)
config.set_section_option(section, 'DATABASE_URL', DATABASE_URL)


# Interpret the config file for Python logging.
Expand Down
14 changes: 14 additions & 0 deletions src/auth/routers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from fastapi import APIRouter

from src.auth.base_config import auth_backend, fastapi_users
from src.auth.schemas import UserCreateInput, UserCreateOutput

router = APIRouter(
prefix="/auth",
tags=["Auth"],
)

router.include_router(fastapi_users.get_auth_router(auth_backend),)
router.include_router(fastapi_users.get_register_router(
UserCreateInput, UserCreateOutput
))
14 changes: 4 additions & 10 deletions src/auth/schemas.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime
import uuid

from fastapi_users import schemas


class UserRead(schemas.BaseUser[int]):
id: int
class UserCreateOutput(schemas.BaseUser[int]):
id: uuid.UUID
email: str
username: str
is_active: bool = True
is_superuser: bool = False
is_verified: bool = False
Expand All @@ -15,11 +14,6 @@ class Config:
orm_mode = True


class UserCreate(schemas.BaseUserCreate):
created_at: datetime
class UserCreateInput(schemas.BaseUserCreate):
email: str
password: str
is_active: bool | None = True
is_superuser: bool | None = False
is_verified: bool | None = False

4 changes: 4 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
DB_PASS = os.environ.get("DB_PASS")

SECRET_AUTH = os.environ.get("SECRET_AUTH")

DATABASE_URL = (
f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)
3 changes: 1 addition & 2 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base
from sqlalchemy.orm import sessionmaker

from src.config import DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER
from src.config import DATABASE_URL

DATABASE_URL = f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
Base: DeclarativeMeta = declarative_base()


Expand Down
22 changes: 9 additions & 13 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from fastapi import FastAPI
from fastapi import APIRouter, FastAPI

from src.auth.base_config import auth_backend, fastapi_users
from src.auth.schemas import UserCreate, UserRead
from src.auth.routers import router as auth_router

app = FastAPI(title="social networking application", docs_url="/")

app.include_router(
fastapi_users.get_auth_router(auth_backend),
prefix="/auth",
tags=["Auth"],
app = FastAPI(
title="social networking application",
docs_url="/",
)

app.include_router(
fastapi_users.get_register_router(UserRead, UserCreate),
prefix="/auth",
tags=["Auth"],
)
main_router = APIRouter(prefix='/api/v1')
main_router.include_router(auth_router)

app.include_router(main_router)

0 comments on commit e500e68

Please sign in to comment.