This API works as a registration and management system. It was developed with node.js, koaJS, and typeORM. The API is integrated with a PostgreSQL database. It is deployed to an EC2 instance.
- Users Authentication
- Account Editing
- Users Listing (if user is admin)
- Backend: Node.js, TypeORM, KoaJS
- Database: PostgreSQL
- Authentication: JWT, AWS Cognito
- Others: Docker, GitHub Actions
The API uses JWT for authentication. After signing in or registering, a token will be returned. To access protected endpoints, include the token in the request header, the /auth and / routes are public, and the /me, /edit-account, and /users are protected/private.
You can send requests to the API running on an EC2 instance by requesting the 56.124.75.60 address on the 3000 port.
- GET
/- Description: Hello World endpoint.
- Response:
{ "message": "Hello, World!" }
- POST
/auth- Description: The endpoint acts as a signInOrRegister. Authenticate the user using and return a JWT token.
- Body:
{ "name": "Tester", "email": "[email protected]", "password": "Passw@rd123" } - Response:
{ "message": "User authenticated", "token": "valid_token", "user":{ "id":1, "email": "[email protected]", "name": "Tester", "role": "user", "isOnboarded": false, "createdAt": "now", "updatedAt": "now", "deletedAt": null } }
- GET
/me- Description: Retrieve user's info.
- Response:
{ "user": { "sub": "something", "cognito:groups": [ "user" ], "email_verified": true, "iss": "something", "cognito:username": "something", "origin_jti": "something", "aud": "somethin", "event_id": "something", "token_use": "id", "auth_time": something, "name": "Tester", "exp": something, "iat": something, "jti": "something", "email": "[email protected]" }
- GET
/users- Description: Return a list of the users registered, only admins are allowed.
- Response:
[ "user":{ "id":1, "email": "[email protected]", "name": "Tester", "role": "user", "isOnboarded": false, "createdAt": "some-date", "updatedAt": "some-date", "deletedAt": null }, "user":{ "id":2, "email": "[email protected]", "name": "Tester2", "role": "admin", "isOnboarded": true, "createdAt": "some-date", "updatedAt": "some-date", "deletedAt": null } ]
- PUT
/users/edit-account- Description: If the user is an admin it can edit the user's role, otherwise only the name is editable. Upon editing the onboarding status is set to true.
- Body:
{ "name": "Tester2", } - Response:
{ "message": "Account updated", "user":{ "id":2, "email": "[email protected]", "name": "Tester2", "role": "admin", "isOnboarded": true, "createdAt": "some-date", "updatedAt": "now", "deletedAt": null } }