I am trying to build a fairly standard Ionic 2 app that uses JWT with my own backend Json API.
Does anyone know where to find a complete example of how this code would look in the latest Ionic 2. I found the angular2-jwt plugin, but their code didn’t work in Ionic 2 RC0, and while I have found bits and pieces of answers on other threads, I am not experienced enough to piece everything together on my own.
Basically, the site just needs to have a login page, a restricted area (that you have to be logged in to access), and store the JWT and user data in storage of some sort. I would imagine that this is pretty standard functionality for an Ionic app so I hope that someone can help me with the code samples and actual file names of where to put the code.
A fantastic tutorial came out yesterday and it was a great help to me solving this, so I’ll post the link here:
My confusion was mostly around not knowing how to make an duse providers/services, and also how to use ionic’s storage instead of localStorage (angular2-jwt’s default). It turns out I really didn’t even need angular2-jwt and I opted for my own auth service (as per the tutorial) to do the job.
The only piece I would still like to add to my app is routes (for each ionic page) with auth guarding for each of the private routes. This would enable me to redirect to a login page immediately based on route. I don’t think routes are possible yet in Ionic 2 RC0 unfortunately.