The main function of the Auth service is to provide functionalites of Sign Up, Sign In and Sign Out.
There are two ways of implementing authentication :
- Stateful authentication using sessions.
- Stateless authentication using signed token.
Stateless Authentication is used to make it scalable.
JWT (JSON Web Token) are sent as a cookie to the clients so that their further requests could be authorized.
Although noSQL database is used but a proper Schema is maintained.
Attribute | Type | Description |
---|---|---|
_id | ObjectId | unique object id of a user (Primary Key) |
string | email id of user | |
userName | string | unique userName of user |
password | string | password of user |
isAuth | boolean | If spotify has been authorized or not |
Registers a new user, and sends a UserCreatedEvent .
POST /api/auth/signup
Signs in a user, by sending a JWT as a cookie to the client.
POST /api/auth/signin
Logs out the user by removing the cookie.
POST /api/auth/signin
It is fired whenever a new user signs up .
Attribute | Type | Description |
---|---|---|
userId | string | _id of UserCollection |
string | email id of user | |
userName | string | unique userName of user |
Handlers consumes events from NATS stream and processes them.
It captures the UserAuthorized Event and processes it and makes isAuth field of UserCollection true.