A full-stack authentication system built with .NET 9 Web API and React TypeScript frontend.
- User Registration & Login: Secure user authentication with JWT tokens
- Password Hashing: BCrypt password hashing for security
- JWT Authentication: Token-based authentication with configurable expiration
- Protected Routes: Frontend route protection based on authentication status
- Modern UI: React with TypeScript and Redux Toolkit for state management
- Database Integration: PostgreSQL with Entity Framework Core
- API Documentation: Swagger/OpenAPI documentation
- .NET 9 - Web API framework
- Entity Framework Core - ORM for database operations
- PostgreSQL - Database
- JWT Bearer Authentication - Token-based authentication
- BCrypt.Net - Password hashing
- Swagger - API documentation
- React 19 - Frontend framework
- TypeScript - Type safety
- Redux Toolkit - State management
- RTK Query - API state management
- React Router - Client-side routing
- Vite - Build tool and dev server
├── Auth.API/ # .NET Web API Backend
│ ├── Controllers/ # API controllers
│ ├── DTOs/ # Data transfer objects
│ ├── Entities/ # Database entities
│ ├── Services/ # Business logic services
│ ├── Data/ # Database context
│ └── Program.cs # Application entry point
├── Auth.Web/ # React Frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── services/ # API services
│ │ └── app/ # Redux store
│ └── package.json
└── README.md
- .NET 9 SDK
- Node.js (v18 or higher)
- PostgreSQL (v12 or higher)
- Install PostgreSQL and create a database
- Update the connection string in
Auth.API/appsettings.json
:{ "ConnectionStrings": { "DefaultConnection": "Host=localhost;Port=5432;Database=your_db;Username=your_user;Password=your_password" } }
-
Navigate to the API directory:
cd Auth.API
-
Restore dependencies:
dotnet restore
-
Apply database migrations:
dotnet ef database update
-
Run the API:
dotnet run
The API will be available at http://localhost:5057
-
Navigate to the web directory:
cd Auth.Web
-
Install dependencies:
npm install
-
Create environment file:
cp .env.example .env
-
Update the
.env
file with your API URL:VITE_API_URL=http://localhost:5057
-
Start the development server:
npm run dev
The frontend will be available at http://localhost:5173
POST /api/auth/login
- User loginPOST /api/auth/register
- User registration
GET /api/users/me
- Get current user profile (protected)
Configure JWT settings in Auth.API/appsettings.json
:
{
"Jwt": {
"Key": "your-secret-key-here",
"Issuer": "your-issuer",
"Audience": "your-audience"
}
}
The API is configured to allow requests from http://localhost:5173
. Update the CORS policy in Program.cs
if needed.
# Backend tests
cd Auth.API
dotnet test
# Frontend tests
cd Auth.Web
npm test
# Backend
cd Auth.API
dotnet publish -c Release
# Frontend
cd Auth.Web
npm run build
- Password Hashing: Uses BCrypt with salt for secure password storage
- JWT Tokens: Secure token-based authentication with configurable expiration
- Input Validation: Server-side validation for all endpoints
- CORS Protection: Configured CORS policy for frontend access
- HTTPS: HTTPS redirection enabled in production
When running in development mode, Swagger documentation is available at:
http://localhost:5057/swagger
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please open an issue on the GitHub repository.