A modern, production-ready authentication template built with AdonisJS v6. This starter provides a complete user authentication system with API endpoints, email integration, and TypeScript support - perfect for building headless applications with separate frontend frameworks like Nuxt, React, or Vue.
-
Complete Authentication System
- User registration and login
- Password reset with email tokens
- JWT token-based authentication
- User profile management
- Admin user auto-creation
-
Security First
- Password hashing with Scrypt
- Token-based authentication
- Input validation with VineJS
- CORS support
-
Developer Experience
- TypeScript throughout
- Hot Module Replacement (HMR)
- Comprehensive test setup with Japa
- ESLint and Prettier configured
- Modular architecture
-
Email Integration
- Password reset emails
- MJML templates for beautiful emails
- Event-driven email notifications
- Node.js (v18 or higher)
- PostgreSQL database
- SMTP server for email functionality
-
Clone the repository
git clone https://github.com/czepter/adonisjs-auth-starter.git cd adonisjs-auth-starter
-
Install dependencies
npm install # or pnpm install
-
Environment setup
cp .env.example .env
Configure your environment variables:
# Database DB_HOST=localhost DB_PORT=5432 DB_USER=your_db_user DB_PASSWORD=your_db_password DB_DATABASE=your_db_name # Application APP_KEY=your_app_key PORT=3333 HOST=localhost LOG_LEVEL=info # Mail SMTP_HOST=your_smtp_host SMTP_PORT=587 SMTP_USERNAME=your_email SMTP_PASSWORD=your_password # Frontend FRONTEND_URL= FRONTEND_URL_VERIFY= FRONTEND_URL_RESET_PASSWORD=
-
Generate application key
node ace generate:key
-
Run database migrations
node ace migration:run
-
Start the development server
npm run dev
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST | /api/v1/auth/register |
Register new user | No |
POST | /api/v1/auth/login |
User login | No |
POST | /api/v1/auth/logout |
User logout | Yes |
POST | /api/v1/auth/forgot-password |
Request password reset | No |
POST | /api/v1/auth/reset-password |
Reset password with token | No |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET | /api/v1/me |
Get current user | Yes |
PUT | /api/v1/me |
Update current user | Yes |
Run the test suite:
npm test
The project includes comprehensive tests for:
- Authentication endpoints
- User management
- Service layer functionality
- Input validation
βββ app/
β βββ controllers/ # HTTP controllers
β βββ models/ # Database models
β βββ services/ # Business logic
β βββ validators/ # Input validation
β βββ dtos/ # Data transfer objects
β βββ events/ # Application events
β βββ listeners/ # Event listeners
βββ database/
β βββ migrations/ # Database migrations
βββ tests/
β βββ functional/ # API endpoint tests
β βββ unit/ # Unit tests
βββ start/
βββ routes.ts # Route definitions
βββ kernel.ts # Middleware setup
βββ events.ts # Event bindings
The first registered user automatically becomes an admin. Subsequent users are regular users by default.
Email templates are located in resources/views/emails/
and use MJML for responsive design.
The application dispatches events for:
- User registration (
UserRegistered
) - User login (
UserLoggedIn
) - Password changes (
UserPasswordChanged
) - Password reset requests (
UserPasswordResetRequested
) - Password resets (
UserPasswordReset
) - User verification (
UserVerified
) - User updates (
UserUpdated
)
-
Build the application
npm run build
-
Start in production
npm start
-
Environment variables Ensure all production environment variables are properly set, especially:
- Database connection
- SMTP configuration
- APP_KEY for security
- Fork the repository
- Create your 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.
- Built with AdonisJS - The Node.js framework for building scalable applications
- Authentication powered by @adonisjs/auth
- Database ORM by @adonisjs/lucid
- Email templates with MJML
If you have any questions or need help getting started, please:
- Check the AdonisJS documentation
- Open an issue on GitHub
- Join the AdonisJS Discord
Happy coding! π