hamidukarimi/authforge-client(新しいタブで開きます)
主要言語: TypeScript
Clean and scalable auth frontend starter, React, TypeScript, Zod, TanStack Query, Zustand, Framer Motion.
- star 数
- 10
- watcher 数
- 0
- fork 数
- 1
- issue 数
- 0
- 最終更新
- 2026/03/12
主要言語: TypeScript
Clean and scalable auth frontend starter, React, TypeScript, Zod, TanStack Query, Zustand, Framer Motion.
A clean and scalable authentication frontend starter built with React and TypeScript. Includes login, registration, protected routes, token refresh, and session management — ready to drop into any project.
sessionStoragehttpOnly cookie (handled automatically)| Tool | Purpose |
|---|---|
| React 19 + Vite | UI framework & build tool |
| TypeScript | Type safety (strict mode) |
| Tailwind CSS v4 | Styling |
| TanStack Query | Server state & mutations |
| Zustand | Global client state |
| Axios | HTTP client + interceptors |
| React Hook Form | Form management |
| Zod | Schema validation |
| Framer Motion | Animations |
| React Router v7 | Routing & navigation |
src/ ├─ api/ │ ├─ axios.ts # Axios instance + token interceptors │ └─ endpoints.ts # All API endpoint constants │ ├─ features/ │ ├─ auth/ │ │ ├─ components/ │ │ │ ├─ LoginForm.tsx │ │ │ └─ RegisterForm.tsx │ │ ├─ hooks/ │ │ │ ├─ useLogin.ts │ │ │ └─ useRegister.ts │ │ ├─ schemas/ │ │ │ ├─ login.schema.ts │ │ │ └─ register.schema.ts │ │ ├─ services/ │ │ │ └─ auth.service.ts │ │ └─ types/ │ │ └─ auth.types.ts │ │ │ ├─ dashboard/ │ │ ├─ components/ │ │ │ └─ DashboardCard.tsx │ │ └─ pages/ │ │ └─ DashboardPage.tsx │ │ │ └─ user/ │ ├─ components/ │ │ └─ ChangePasswordForm.tsx │ ├─ hooks/ │ │ └─ useChangePassword.ts │ ├─ schemas/ │ │ └─ changePassword.schema.ts │ ├─ services/ │ │ └─ user.service.ts │ └─ types/ │ └─ user.types.ts │ ├─ components/ │ ├─ ui/ │ │ ├─ Button.tsx │ │ ├─ Input.tsx │ │ ├─ Spinner.tsx │ │ └─ Alert.tsx │ └─ layout/ │ ├─ Navbar.tsx │ ├─ ProtectedRoute.tsx │ └─ PublicRoute.tsx │ ├─ context/ │ └─ AuthContext.tsx │ ├─ hooks/ │ ├─ useAuth.ts │ └─ useLogout.ts │ ├─ lib/ │ └─ queryClient.ts │ ├─ pages/ │ ├─ LoginPage.tsx │ ├─ RegisterPage.tsx │ └─ NotFoundPage.tsx │ ├─ routes/ │ └─ AppRouter.tsx │ ├─ store/ │ └─ authStore.ts │ ├─ types/ │ └─ api.types.ts │ └─ utils/ ├─ token.ts └─ errorHandler.ts
POST /api/users — registerPOST /api/sessions — loginPOST /api/token — refresh access token (via httpOnly cookie)POST /api/logout — logoutPOST /api/logout/all — logout all devicesPUT /api/users/me/password — change passwordThis frontend is designed to work with authforge-express but can be adapted to any backend.
git clone https://github.com/hamidukarimi/authforge-client.git
cd authforge-clientnpm install
VITE_API_URL=http://localhost:5000
npm run dev
The app runs on http://localhost:5173 by default.
Login / Register
↓
API returns { user, accessToken }
↓
accessToken → sessionStorage
user → Zustand store
refreshToken → httpOnly cookie (set by backend)
↓
On page refresh → ProtectedRoute calls /api/token
→ new accessToken issued from cookie
→ user restored from response
↓
On 401 error → Axios interceptor auto-refreshes token
→ failed requests retried automatically
↓
On logout → token cleared, store cleared, cookie deleted
Feature-based structure — each feature (auth, user, dashboard) owns its own components, hooks, services, schemas, and types. Easy to scale, easy to delete.
Axios interceptor — handles token refresh silently. If a request fails with 401, the interceptor calls /api/token, gets a new access token, and retries the original request — all without the user noticing.
Zustand for auth state — lightweight global state for user and isAuthenticated. No boilerplate, no context prop drilling.
Zod as single source of truth — form validation schemas also export their inferred TypeScript types, so there's no duplication between Zod schemas and TypeScript interfaces.
sessionStorage for access token — access tokens are cleared when the browser tab closes. Refresh tokens live in httpOnly cookies managed entirely by the backend.
| Variable | Description | Example |
|---|---|---|
VITE_API_URL |
Base URL of your backend API | http://localhost:5000 |
npm run dev # Start development server npm run build # Build for production npm run preview # Preview production build npm run lint # Run ESLint
To connect to a different backend:
src/api/endpoints.ts with your API routessrc/types/api.types.ts to match your user shapesrc/features/auth/types/auth.types.ts with your payload shapessrc/features/auth/schemas/ to match your validation rulesContributions are welcome! Feel free to open issues or submit pull requests.
git checkout -b feature/my-feature
git commit -m "feat: add my feature"
git push origin feature/my-featureThis project is licensed under the MIT License. See the LICENSE file for details.
If you find this project useful, consider giving it a star ⭐ on GitHub.
Made with ❤️ by Hamid Karimi