This project demonstrates a simple authentication system using Next.js, React, and JSON Web Tokens (JWT). It features a modern, responsive login interface with a glassmorphism design.
- User authentication with JWT
- Server-side rendering with Next.js
- Responsive design for all screen sizes
- Modern UI with gradient and glassmorphism effects
- Next.js 14
- React
- TypeScript
- CSS Modules
- jose (for JWT handling)
- Node.js (v14 or later)
- npm or yarn
-
Clone the repository:
git clone https://github.com/your-username/nextjs-auth-demo.git
-
Navigate to the project directory:
cd nextjs-auth-demo
-
Install dependencies:
npm install
or
yarn install
-
Run the development server:
npm run dev
or
yarn dev
-
Open http://localhost:3000 in your browser to see the result.
app/
: Contains the main application pages and componentslib/
: Houses utility functions for authentication and session managementstyles/
: Includes global styles and CSS modules
app/layout.tsx
: The root layout componentapp/page.tsx
: The main page component with login/logout functionalitylib.ts
: Utility functions for JWT encryption, decryption, and session management
- User enters email and submits the login form
- Server-side action creates a session with JWT
- Session is stored in an HTTP-only cookie
- User can log out, which clears the session cookie
The project uses CSS Modules for component-specific styling. The login interface features:
- Gradient background
- Glassmorphism effect for the login box
- Responsive design for various screen sizes
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.