Skip to content

0.6.0

Choose a tag to compare

@igorbenav igorbenav released this 21 Nov 01:37
· 253 commits to main since this release
d9c978f

0.6.0 Summary

 🚀Features

  • Token blacklist (possibility to log out users)

📝Docs

0. New Token Blacklist Model

diagram
To log users out, a token blacklist was created. Now you can invalidate a token at any moment. To do so, verify_token function (also schemas and CRUD) created.

🚚Migration

0. Update user table definition in create_first_superuser.py

If you change the user model, you must also update the table definition in src/scripts/create_first_superuser.py in order for it to keep working.

Here is the table definition:

# src/scripts/create_first_superuser.py
...
if user is None:
        metadata = MetaData()
        user_table = Table(
            "user", metadata,
            Column("id", Integer, primary_key=True, autoincrement=True, nullable=False),
            Column("name", String(30), nullable=False),
            Column("username", String(20), nullable=False, unique=True, index=True),
            Column("email", String(50), nullable=False, unique=True, index=True),
            Column("hashed_password", String, nullable=False),
            Column("profile_image_url", String, default="https://profileimageurl.com"),
            Column("uuid", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=True),
            Column("created_at", DateTime, default=datetime.utcnow, nullable=False),
            Column("updated_at", DateTime),
            Column("deleted_at", DateTime),
            Column("is_deleted", Boolean, default=False, index=True),
            Column("is_superuser", Boolean, default=False),
            Column("tier_id", Integer, ForeignKey("tier.id"), index=True)
        )

Let's say you added a column in your user model, age.

...
class User(Base):
    __tablename__ = "user"

    ...
    # --------- here the new `age` column was added ---------
    age: Mapped[Optional[int]] = mapped_column(default=None)
    # -------------------------------------------------------
    ...

I'll now update the table definition in create_first_superuser.py accordingly:

# src/scripts/create_first_superuser.py
...
if user is None:
        metadata = MetaData()
        user_table = Table(
            "user", metadata,
            ...
            Column("age", Integer, nullable=True, default=None),
            ...
        )

1. Token Blacklist

This should work out of the box, all you need to do is run the alembic migration.

While in the src folder:

poetry run alembic revision --autogenerate

And to apply the migration

poetry run alembic upgrade head

3. Middleware folder

Now you can create your middleware in the app/middleware folder. Client-side cache was moved there.

 🔎Bug fixes

  • docs content fixed
  • fixed some type hints
  • some unused imports removed
  • logger being declared twice in rate_limit.py #45
  • create_first_superuser now working again.

Warning

If you change the user model, now you'll also have to change the definition in create_first_superuser script. That happens because the script wasn't working without the relationship definitions, also getting the user model isn't trivial for async. May be fixed eventually.

What's Changed

Full Changelog: v0.5.0...v0.6.0