Skip to content

Active Session

This model is used to store active session for users. It has a one-to-one relationship with User model. If multiple session is not allowed, user has to login again on any new device.

Bases: Base

Active session model

Source code in FasterAPI\models.py
class ActiveSession(Base):
    """Active session model""" ""

    __tablename__ = "active_sessions"
    id: Mapped[int] = mapped_column(primary_key=True, index=True)
    username: Mapped[str] = mapped_column(
        ForeignKey("users.username"), index=True, unique=True
    )
    client: Mapped[str]
    exp: Mapped[datetime]
    user: Mapped["User"] = relationship("User", back_populates="session")

__tablename__ = 'active_sessions' class-attribute instance-attribute

client: Mapped[str] instance-attribute

exp: Mapped[datetime] instance-attribute

id: Mapped[int] = mapped_column(primary_key=True, index=True) class-attribute instance-attribute

user: Mapped[User] = relationship('User', back_populates='session') class-attribute instance-attribute

username: Mapped[str] = mapped_column(ForeignKey('users.username'), index=True, unique=True) class-attribute instance-attribute