- Install Node.js v22.
- Clone this repository and navigate to the
auth-servicedirectory:cd ./auth-service - Install the dependencies:
npm i
- Start the server:
npm run start
- Or run unit tests with
npm test - The server will start on
http://localhost:8000/
Ensure you set up the following environment variables in a .env file:
ACCESS_TOKEN_SECRET=your-secret-key
REFRESH_TOKEN_SECRET=your-refresh-secret-key
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
DATABASE_URL=your-postgres-db
All endpoints are prefixed with: /auth
GET /auth/google/callback
Google OAuth2 callback. On success, sends a message with the access token to the parent window and closes the popup.
POST /auth/register
Register a new user.
Body:
{
"username": "your-name",
"email": "you@example.com",
"password": "your-password"
}POST /auth/login
Log in an existing user with email and password. Body:
{
"email": "you@example.com",
"password": "your-password"
}POST /auth/token
Generate a new access token using a valid refresh token.
Body:
{
"token": "your-refresh-token"
}The project uses Jest for testing.
Run all tests: npm test