1.4 KiB
1.4 KiB
P1-Frontend: Setup & Authentication Plan
Goal
Finalize frontend setup and implement robust Authentication connecting to the NestJS Backend (P2-2 Refresh Token support).
Status Analysis
- P1-1 (Setup): ✅ Project structure, Tailwind, Shadcn/UI are already present.
- P1-2 (Auth): 🚧
lib/auth.tsexists but lacksrefreshTokenrotation logic. Types need verification.
Proposed Changes
1. Type Definitions (types/next-auth.d.ts)
- Add
refreshToken,accessTokenExpires(optional), anderrorfield toSessionandJWTtypes.
2. Auth Configuration (lib/auth.ts)
- Update
authorizeto storerefresh_tokenfrom Backend response. - Implement
refreshTokenrotation logic injwtcallback:- Check if token is expired.
- If expired, call backend POST
/auth/refresh. - Update
accessTokenandrefreshToken. - Handle refresh errors (Force sign out).
3. Login Page (app/(auth)/login/page.tsx)
- Polish Error Handling (Use Toasts instead of alerts).
- Ensure redirect works correctly.
4. Middleware (middleware.ts)
- Verify middleware protects dashboard routes.
Verification Plan
- Manual Test: Login with valid credentials.
- Inspection: Check LocalStorage/Cookies (NextAuth session cookie).
- Token Rotation: Wait for short access token expiry (if configurable) or manually invalidate, and verify seamless refresh.