Web Auth Serializers

File: api/nextango/apps/web_auth/serializers.py Last Updated: 2026-07-09

Overview

web_auth has two kinds of serializers. Four are read-only response serializers for WebSession, OTPCode, SessionPermission, and User, used to shape API responses. Three are plain Serializer (not ModelSerializer) input validators used by the customer registration views.


WebSessionSerializer

Exposes what an active WebSession model.

Fieldread_onlyDescription
idyesSession UUID
session_typeyesdemo or dashboard
is_guestyesWhether the session has no linked user
emailyesGuest email, null for authenticated sessions
user_idyesuser.id, null for guest sessions
user_emailyesuser.email, sourced from the related user
user_nameyesuser.name, sourced from the related user
created_atyesSession creation timestamp
expires_atyesSession expiration timestamp
last_activityyesLast activity timestamp

All fields are read-only. session_key, ip_address, and user_agent are intentionally excluded from the response.


OTPCodeSerializer

Exposes OTPCode metadata for monitoring and debugging without ever exposing the code itself.

Fieldread_onlyDescription
emailyesRecipient email
purposeyesOTP purpose
created_atyesCreation timestamp
expires_atyesExpiration timestamp
verifiedyesWhether the code has been consumed
attemptsyesFailed verification attempts

code is never included. OTP codes reach the client only through email delivery in OTPService.


SessionPermissionSerializer

Exposes a SessionPermission rule.

Fieldread_onlyDescription
session_typeyesdemo or dashboard
endpoint_patternyesRegex pattern matched against the request path
http_methodsyesAllowed HTTP methods
descriptionyesHuman-readable explanation

Enforcement happens in WebSessionAuthMiddleware, not in this serializer.


UserBasicSerializer

Exposes essential user identity and role information in authentication responses, without password or sync internals.

Fieldread_onlyDescription
idyesUser UUID
emailyesUser email
nameyesDisplay name
first_nameyesFirst name
last_nameyesLast name
statusyesAccount status
rolesyesComputed from user.get_all_roles()
primary_roleyesComputed from user.get_primary_role()
loyalty_pointsyesComputed by scanning user_roles_data for the roleCustomer entry and reading loyaltyPoints; returns 0 if the user has no customer role data
has_passwordyesWhether the user has a password set
is_superuseryesSuperuser flag

Excludes password hash, Sanity sync fields, and audit timestamps.


Registration Input Serializers

These three are plain Serializer classes (not ModelSerializer) used to validate request bodies for the customer registration views. They are writable, not read-only.

InitiateRegistrationSerializer

FieldRequiredDescription
emailyesNormalized to lowercase and trimmed; must be 255 characters or fewer
namenoFull display name; if provided, must be at least 2 characters after trimming
first_namenoTrimmed if provided
last_namenoTrimmed if provided

Used by InitiateRegistrationView.

VerifyRegistrationSerializer

FieldRequiredDescription
emailyesNormalized to lowercase and trimmed
otp_codeyesExactly 6 digits
registration_tokenyesMust start with reg_

Used by VerifyRegistrationView.

ResendOTPSerializer

FieldRequiredDescription
emailyesNormalized to lowercase and trimmed
registration_tokenyesMust start with reg_

Used by ResendOTPView.


Was this page helpful?