← 返回列表
全部 Skill›开发 Development›frontend-auth-module-guideline

frontend-auth-module-guideline

作者 @findsun-vn · 语言 en
Guide Vue auth module generation for login, registration, token/session handling, current-user flow, and route access control.
开发 Development前端开发通用访问网络敏感路径待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
0
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

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/register
  • POST /api/auth/login
  • POST /api/auth/refresh
  • POST /api/auth/logout
  • GET /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.ts
  • frontend/src/modules/auth/stores/auth.store.ts
  • frontend/src/modules/auth/composables/useAuth.ts
  • frontend/src/modules/auth/pages/LoginPage.vue
  • frontend/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 state
  • frontend/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:

  • LoginRequest
  • RegisterRequest
  • RefreshTokenRequest
  • AuthResponse
  • CurrentUserResponse
  • ChangePasswordRequest

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:

  • isAuthenticated
  • currentUser
  • 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
评论
Ffindsun-vn
findsun-vn
findsun-vn/E-Commerce
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@findsun-vn
所属大类开发 Development / 前端开发
国内可用性通用
最近源活动—
风险提示访问网络、敏感路径
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。