feat(): migrate to auth identity

This commit is contained in:
doas root
2025-11-18 00:25:24 +03:00
parent 63a057b020
commit f44e688662
18 changed files with 219 additions and 48 deletions
@@ -0,0 +1,40 @@
from datetime import UTC, datetime
from enum import StrEnum
from typing import NewType, Self
from uuid import UUID
from uuid_utils.compat import uuid7
from template_project.application.common.entity import Entity, to_entity
from template_project.application.user.entity import UserId
AuthIdentityId = NewType("AuthIdentityId", UUID)
class AuthMethod(StrEnum):
EMAIL = "email"
@to_entity
class AuthIdentity(Entity[AuthIdentityId]):
user_id: UserId
method: AuthMethod
identifier: str
secret_key: str | None
@classmethod
def factory(
cls,
user_id: UserId,
method: AuthMethod,
identifier: str,
secret_key: str | None = None,
) -> Self:
return cls(
id=AuthIdentityId(uuid7()),
user_id=user_id,
method=method,
identifier=identifier,
secret_key=secret_key,
created_at=datetime.now(tz=UTC),
)