github-actions[bot]
Automated Deploy: 0d5b759d8eca219a25b3ab717925e73a66bbf4a4
2756f0f
Raw History Blame Contribute Delete
1.64 kB
"""Auth request and response bodies."""
from typing import Annotated, Literal
from email_validator import EmailNotValidError, validate_email
from pydantic import AfterValidator, Field
from app.common.schemas import RequestModel, ResponseModel
from app.modules.accounts.schemas import UserOut
def normalize_email(value: str) -> str:
try:
return validate_email(value.strip(), check_deliverability=False).normalized.lower()
except EmailNotValidError as exc:
raise ValueError("Enter a valid email address.") from exc
Email = Annotated[str, Field(max_length=254), AfterValidator(normalize_email)]
Password = Annotated[str, Field(min_length=8, max_length=128)]
Role = Literal["player", "coach"]
class RegisterIn(RequestModel):
email: Email
password: Password
role: Role
class LoginIn(RequestModel):
email: Annotated[str, Field(min_length=1, max_length=254)]
password: Annotated[str, Field(min_length=1, max_length=128)]
class SocialIn(RequestModel):
provider: Literal["apple", "google"]
id_token: Annotated[str, Field(min_length=1, max_length=8192)]
role: Role = "player"
class RefreshIn(RequestModel):
refresh_token: Annotated[str, Field(min_length=1, max_length=256)]
class ForgotPasswordIn(RequestModel):
email: Email
class ResetPasswordIn(RequestModel):
token: Annotated[str, Field(min_length=1, max_length=256)]
password: Password
class TokensOut(ResponseModel):
access_token: str
refresh_token: str
expires_in: int
class AuthOut(ResponseModel):
user: UserOut
tokens: TokensOut
class SocialAuthOut(AuthOut):
is_new: bool