Prompt Details
Model
(claude-4-7-opus)
Token size
668
Example input
[FRAMEWORK]: React
[LOGIN_ENDPOINT]: /api/auth/login
[TOKEN_EXPIRY]: 15 minutes
[USER_FIELDS]: id, email, name, role
Example output
✅ hooks/useAuth.ts
— useAuth() hook with useState, useEffect, useCallback
— In-memory token store with expiry tracking
— Auto-refresh fires 5 minutes before expiry
— Returns: { user, isLoggedIn, login, logout, error, isLoading }
✅ middleware/auth.ts
— authenticateToken middleware
— Discriminates TokenExpiredError vs JsonWebTokenError
— Extends Express Request with req.user: AuthUser
— Returns 401 with specific error codes per failure type
✅ routes/auth.ts
— POST /auth/login with Zod validation
— POST /auth/refresh with refresh token verification
— Returns { accessToken, refreshToken, user } on success
✅ types/auth.ts
— User, AuthState, LoginCredentials, JWTPayload interfaces
— AuthResponse and AuthError types
— LoginFormValues type for form binding
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-7-OPUS
A senior React + Node.js engineer persona that generates a complete authentication system — useAuth() hook, JWT middleware, login API route, and TypeScript types — all in one output. Specify your framework, API endpoint, token expiry, user fields, and error style. Production-ready code, no placeholders, no TODOs.
...more
Added 4 days ago
