curl -X POST http://localhost:3000/users/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "password123"
}'curl -X POST http://localhost:3000/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'Expected response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "uuid-here",
"email": "test@example.com",
"username": "testuser",
"createdAt": "2025-01-01T00:00:00.000Z"
}
}curl -X GET http://localhost:3000/users/me \
-H "Authorization: Bearer YOUR_JWT_TOKEN_HERE"curl -X GET http://localhost:3000/attempts \
-H "Authorization: Bearer YOUR_JWT_TOKEN_HERE"curl -X GET http://localhost:3000/users/my-stats \
-H "Authorization: Bearer YOUR_JWT_TOKEN_HERE"curl -X GET http://localhost:3000/users/meMake sure to create a .env file based on .env.example:
cp .env.example .envUpdate the values in .env as needed, especially:
JWT_SECRET: Use a strong, unique secret in production- Database credentials
- Install dependencies:
pnpm install-
Set up your PostgreSQL database
-
Run the application:
pnpm run start:devThe following routes are now protected with JWT authentication:
GET /users/me- Get current user profileGET /users/stats/:userId- Get user statisticsGET /users/stats/:userId/rank- Get user rankGET /users/my-stats- Get current user's statisticsGET /attempts- Get user's attemptsPOST /attempts- Create new attemptGET /attempts/my-stats- Get attempt statistics
POST /users/register- User registrationPOST /auth/login- User loginGET /users/leaderboard- Public leaderboard (optional)
// Get full user object
@Get('profile')
async getProfile(@CurrentUser() user: User) {
return user;
}
// Get only user ID
@Get('my-data')
async getMyData(@CurrentUser('id') userId: string) {
return { userId };
}