frontend-auth-module-guideline
Skill: frontend-auth-module-guideline
Purpose
Ensure the frontend authentication module is:
- secure enough for normal application use
- consistent with OpenAPI
- aligned with the single Vue app architecture
- aligned with module-based frontend structure
- easy to integrate with route guards, current-user bootstrap, and token/session flows
Scope
Use this skill when the module is:
auth- or any module that includes:
- login
- register
- logout
- refresh token
- current authenticated user
- password change/reset
- role / permission-based access control
- token/session bootstrap logic
Frontend Architecture Assumption
This project uses:
- one Vue application
- Vue 3
- TypeScript
- Pinia
- Vue Router
- Axios
- Ant Design Vue
Authentication-related business code must live under:
frontend/src/modules/auth/
Standard auth module structure:
api/components/composables/pages/stores/types/routes.ts
Shared generic code belongs under:
frontend/src/shared/
Route guards belong under:
frontend/src/router/guards/
Core Auth Frontend Flows
Typical auth frontend flows may include:
- login
- register
- logout
- token refresh
- current authenticated user bootstrap
- password update/reset
- route protection
- permission-based page access
Only generate flows that are supported by:
- planner output
- OpenAPI contract
Do not invent unsupported auth behavior.
Mandatory Stateless JWT Frontend Strategy
Unless explicitly overridden by approved OpenAPI or higher-level project rules, the frontend auth module MUST assume:
- backend auth is stateless
- access token is sent through:
Authorization: Bearer <access_token>- access token usage is centralized through the shared HTTP client / interceptor flow
- protected-route behavior is driven by auth store state plus current-user bootstrap logic
- cookie-session-based frontend auth assumptions are not the default
Normal protected API calls must not send the access token in:
- query parameters
- request body
- random ad hoc headers
The canonical current-user endpoint is:
GET /api/auth/me
The canonical auth endpoints are:
POST /api/auth/registerPOST /api/auth/loginPOST /api/auth/refreshPOST /api/auth/logoutGET /api/auth/me
These are approved exceptions to plural resource naming.
Auth Module Placement Rules
Module code
Put auth business code under:
frontend/src/modules/auth/
Examples:
frontend/src/modules/auth/api/auth.api.tsfrontend/src/modules/auth/stores/auth.store.tsfrontend/src/modules/auth/composables/useAuth.tsfrontend/src/modules/auth/pages/LoginPage.vuefrontend/src/modules/auth/routes.ts
Shared code
Put only truly generic reusable code under:
frontend/src/shared/api/frontend/src/shared/composables/frontend/src/shared/types/frontend/src/shared/utils/
Do not move auth-specific business logic into shared too early.
Global app integration
Use root/global locations only for app-wide concerns:
frontend/src/router/guards/frontend/src/stores/if there is truly global bootstrap statefrontend/src/layouts/
API Rules
All auth API calls must be placed inside:
frontend/src/modules/auth/api/
Typical files:
auth.api.ts
Typical API functions:
- login
- register
- logout
- refreshToken
- getCurrentUser
- changePassword
- resetPassword
Only generate functions that exist in OpenAPI.
Do not:
- hardcode endpoints outside the API layer
- call Axios directly from pages when auth API functions exist
Response Contract Rules
This project uses the standard API response envelope:
type ApiResponse<T> = {
code: number
message: string
data: T
}
Auth frontend code must always unwrap the payload from:
response.data
Never assume auth payload is top-level raw data.
Auth Types Rules
Keep auth-related request/response types under:
frontend/src/modules/auth/types/
Typical examples:
LoginRequestRegisterRequestRefreshTokenRequestAuthResponseCurrentUserResponseChangePasswordRequest
If OpenAPI defines different names, follow OpenAPI exactly.
Keep only generic reusable types under:
frontend/src/shared/types/
Examples of shared generic types:
ApiResponse<T>PageResponse<T>
Auth Store Rules
The auth store should normally live under:
frontend/src/modules/auth/stores/auth.store.ts
It may manage:
- authenticated user
- access token / session state
- login/logout actions
- current-user bootstrap
- refresh flow integration
- auth loading/error state
Use frontend/src/stores/ only if there is a clearly global app bootstrap store.
Do not split auth state arbitrarily between module store and global store without reason.
Auth store responsibilities
- call auth API functions
- persist/clear token/session data according to app rules
- fetch current user when needed
- expose auth status to UI
- support logout cleanup
Auth store must not
- embed raw endpoint strings
- duplicate all logic in many pages
- expose sensitive values to UI unnecessarily
Mandatory Auth Store Responsibilities
The auth store MUST centralize at minimum:
- access token/session presence state
- current authenticated user
- login action
- register action when applicable
- logout action and cleanup
- current-user bootstrap
- auth loading state
- auth error state
The auth store SHOULD be the only business source of truth for:
isAuthenticatedcurrentUser- auth bootstrap completion
- logout/session-clear behavior
Do not duplicate these responsibilities across unrelated stores, pages, and guards.
If refresh token support exists in OpenAPI:
- refresh behavior must remain centra
