Developer Resourcesauth
Auth Module Backend Documentation
Internal auth architecture with split admin/customer controllers and Google OAuth customer-only behavior.
Auth - Backend Documentation
1. Module Scope
Shared AuthModule provides auth primitives used by two HTTP surfaces:
- Admin controller:
/api/auth/* - Mobile customer controller:
/api/mobile/auth/*
Core responsibilities:
- email/password auth
- session/token issuance + refresh/logout
- email/phone verification flows
- password reset flows
- customer Google OAuth login/linking/signup
2. Composition
2.1 Controllers
apps/api/src/modules/auth/auth.controller.ts- admin/backoffice auth routes
- no Google OAuth endpoints
apps/api/src/modules/mobile/auth/auth.controller.ts- customer/mobile auth routes
- owns Google OAuth endpoints (
google,google/callback)
2.2 Strategies and guards
LocalStrategy+LocalAuthGuardfor admin email loginJwtStrategy+JwtAuthGuardfor protected routesGoogleStrategy+GoogleAuthGuardfor customer Google OAuth flow
2.3 Core services
AuthServiceAuthSessionServiceAuthUserQueryServiceAuthTokenServiceAuthEmailServiceVerificationTokenService
3. Google OAuth Execution Path (Customer Only)
GET /api/mobile/auth/googletriggersGoogleAuthGuardredirect.- Google calls
GET /api/mobile/auth/google/callback. GoogleStrategy.validate()returns profile payload (id,email,displayName,photoUrl) and provider tokens.AuthService.handleGoogleOAuth()applies runtime rules:- reject missing email
- reject if email belongs to admin user
- find existing customer by email
- upsert/link Google
accountrow - auto-mark customer
emailVerified=truewhen needed - auto-create customer + Google account when customer does not exist
- Service issues session + tokens via existing auth issuance path.
- Mobile controller returns
ResponseDto("Google login successful.", { user, tokens }).
4. Data Model Effects
Tables touched in Google flow:
customersadmin_users(lookup check only)accountcustomer_sessions
Write behavior:
- Existing linked customer: updates account token columns.
- Existing unlinked customer: creates Google provider link row in
account. - Existing unverified customer: updates
customers.email_verified = true. - New customer: inserts into
customersand inserts provider link intoaccount.
5. Behavior Clarifications
5.1 New user via Google
Customer is auto-signed-up (customer row created), then logged in immediately.
5.2 Existing customer with pending email verification
Successful Google login on same email upgrades account to verified and logs user in.
5.3 Admin account attempting Google login
Rejected with unauthorized response; admin must use email/password flow.
6. Configuration
Google config keys:
GOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETGOOGLE_CALLBACK_URL
Expected callback route:
http://<host>:<port>/api/mobile/auth/google/callback
7. Security and Operational Controls
- DTO validation via global
ValidationPipe - endpoint throttling via
IpThrottlerGuard+@IpThrottle - banned-user protection via user-query checks
- token/session rotation centralized in session service
This keeps Google flow aligned with the same session issuance policy as email login.