Now that our authentication is completed, we can work on consuming API tokens within our application. Tokens are important to limit access to our application.
In this lesson, we will:
- Store the token in our Auth Provider
- Add Headers to our API requests - including the token
- Refactor our API Service to use the token
- And some other minor changes
Let's start by refactoring our API service to use the token.
Refactoring API Service - Consuming API Tokens
Currently, we have no way to pass the token to our API service, so let's add that:
Note: We will declare the token as a [non-nullable variable] using the...
I found some errors:
lib/services/api.dartin the methodFuture saveCategory(Category category)theheaderswas added in thebody.lib/providers/auth_provider.dartI've updated the
saveCategorymethod to be correct, thanks!As for the changes - they did not impact the code at this point (for example, the removal of
returnhas 0 impact at this current stage) :)You did not mention changes in lib/providers/auth_provider.dart, I checked "Github Commits" to know what was the changes
Those changes are not that inportant if I'm being honest. These were precautionary changes, but it works without them (at least it worked when the tutorial was made). If it does not work - I can update the lesson!
The addition of AuthProvider token is important!
Oh! Terribly sorry, I completely missed that specific line and focused on the return types/returns.
Indeed then I missed it three times... Will update the lesson tomorrow.
Updated the lesson