A modern, responsive authentication frontend built with React, TypeScript, and Tailwind CSS that integrates with the Laravel authentication API.
- Modern UI/UX: Clean, responsive design with Tailwind CSS
- TypeScript: Full type safety throughout the application
- Authentication: Complete login/register system with token management
- Protected Routes: Automatic redirection based on authentication status
- Cookie Management: Secure token storage with js-cookie
- API Integration: Seamless communication with Laravel backend
- React Router: Client-side routing with protected routes
- React 18 - Modern React with hooks
- TypeScript - Type-safe JavaScript
- Vite - Fast build tool and dev server
- Tailwind CSS - Utility-first CSS framework
- React Router DOM - Client-side routing
- Axios - HTTP client for API requests
- js-cookie - Cookie management
- React Context - State management for authentication
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:5173
src/
├── components/ # React components
│ ├── Home.tsx # Landing page
│ ├── Login.tsx # Login form
│ ├── Register.tsx # Registration form
│ ├── Dashboard.tsx # Protected dashboard
│ └── ProtectedRoute.tsx # Route protection wrapper
├── contexts/ # React contexts
│ └── AuthContext.tsx # Authentication context
├── lib/ # Utility libraries
│ └── api.ts # API client and auth functions
├── App.tsx # Main app component with routing
└── main.tsx # App entry point
- Registration: Users can create new accounts
- Login: Existing users can sign in
- Token Management: JWT tokens are stored in HTTP-only cookies
- Protected Routes: Dashboard requires authentication
- Auto-redirect: Users are redirected based on auth status
- Logout: Secure logout with token cleanup
The frontend communicates with the Laravel backend at http://localhost:8000/api
:
- POST
/register
- User registration - POST
/login
- User login - POST
/logout
- User logout - GET
/me
- Get current user
Make sure your Laravel backend is running on http://localhost:8000
before starting the frontend.
npm run dev
- Start development servernpm run build
- Build for productionnpm run preview
- Preview production buildnpm run lint
- Run ESLint
- Landing page with feature highlights
- Automatic redirect to dashboard if authenticated
- Links to login and register pages
- Email and password authentication
- Form validation and error handling
- Link to registration page
- User registration with name, email, and password
- Password confirmation validation
- Link to login page
- Protected route requiring authentication
- User information display
- Logout functionality
- Quick action buttons
The AuthContext
provides:
- User state management
- Authentication status
- Login/logout functions
- Token management
- Loading states
The API client (lib/api.ts
) handles:
- HTTP requests to Laravel backend
- Automatic token attachment
- Error handling and token expiration
- Response interceptors
The ProtectedRoute
component:
- Checks authentication status
- Redirects unauthenticated users to login
- Shows loading state during auth check
- Wraps protected components
The application uses Tailwind CSS for styling with:
- Responsive design
- Modern UI components
- Consistent color scheme
- Accessibility features
- Token-based authentication
- Secure cookie storage
- Automatic token refresh
- Protected route handling
- CSRF protection (handled by Laravel)
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- The app uses React Router for client-side routing
- All components are functional components with hooks
- TypeScript strict mode is enabled
- ESLint configuration follows React recommendations
- Vite provides fast HMR (Hot Module Replacement)
This React frontend provides the same functionality as the Next.js frontend but with:
- Client-side routing instead of server-side routing
- Vite instead of Next.js build system
- React Router instead of Next.js App Router
- Simpler setup for pure React applications
- Faster development with Vite's HMR
Both frontends can work with the same Laravel backend API!