Today I continue the adventure with the Authentication the Collectively application. On the last post I show how to use axios, how to save the JWT token to LocalStorage and how to create form and call function with parameters to call the function to POST the data from the form to API.

In order to Authenticate via email in Collectively, it is necessary to prepare also HEADERS in the Request. More about headers you can read here. In shortcut, API requires providing some special header. Going through the documentation I had some issue which taken me a long time, and the answer was easy – I need also in my Body prepare “provider”, without that I have the HTTP 400 error. The worst error which you can ever meet!

After a long fight with documentation, Now the API send me a response, I can save my token and everything works fine.

The response looks like:

  "token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJTdWIiOiI2YWU2ZTRmNmRmZWM0YWU5YWI3OGViNDg1NGRiNmE2ZCIsIkV4cCI6NjM2MzYxNjMwODc4OTcyNzIwfQ.-osi2MuGza6DMnRwJv4js_3DgcbGUHRA7G7hZSoI1JCLQ9q5rXorV0wkGGKzVyO6YP9xGjOzWH2ZoTHvnzEBEw",
  "sessionId": "34be9e04-bc1d-4f47-9956-75cd2a61ca73",
  "sessionKey": "yxTg1XDsKdqJASsivnxJEkpytDRJAYPw3GulUCBEb22aOC1Bh1FKjKNHrQTlEBLHm5xjfyY",
  "expiry": 1500566287897

And that’s all. Surely, the most important thing in the handle with authentication was written in this 2 parts. Now everything working well and I can go further through the documentation and add new amazing features!

Patyk Huzarski

Freelance web developer, addicted to computer engineering.