Skip to content

feat(auth): add role to auth model, improve user store and align mocks#1

Open
isatian-36 wants to merge 1 commit intomainfrom
codex/explain-contents-of-src/router/routes-directory
Open

feat(auth): add role to auth model, improve user store and align mocks#1
isatian-36 wants to merge 1 commit intomainfrom
codex/explain-contents-of-src/router/routes-directory

Conversation

@isatian-36
Copy link
Owner

Motivation

  • Align role model across API, store and examples so login returns a concrete role used for route/menu filtering.
  • Provide reusable user helpers in the store to centralize role checks and allow setting user data from login response without extra plumbing.
  • Make mock endpoints consistent with admin / operator roles so UI/dev flows can reliably exercise role-based behavior.

Description

  • Added UserRole and extended AuthType with role in src/api/user/types.ts and preserved roles on UserInfoType for compatibility, enabling typed role handling in the app.
  • Updated auth store initial shape to include role and continue to persist token, refreshToken and role via zustand/persist in src/store/auth.ts so persisted shape stays stable.
  • Rewrote src/store/user.ts to add setUserInfo, hasRole and keep getUserInfo/reset, centralizing user state mutations and role checks for UI use.
  • Adjusted route example and mocks to the new role naming: src/router/routes/modules/access.ts (use operator instead of common), fake/auth.fake.ts, fake/user.fake.ts, and fake/async-routes.fake.ts to return/consume role consistently for admin/operator scenarios.
  • Added a short summary doc docs/zh/ecommerce-auth-implementation.md describing the login/token/401/dynamic-route flow and notes about using the existing ky request layer or swapping to axios later.

Testing

  • Ran TypeScript checks with pnpm typecheck (tsc --noEmit) and the typecheck completed successfully against the modified codebase.
  • Pre-commit lint hooks ran eslint --fix on staged files as part of the commit flow and completed (auto-fixes applied to staged files).
  • Attempted to install axios for an alternate example (pnpm add axios) but the registry returned 403 in this environment so axios was not added; the repository continues to use the existing ky request layer.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments