IbrahimDevp / flutter_auth

0 stars 0 forks source link

Splitting accessToken from ChangeNotifier #10

Open adnsawas opened 1 year ago

adnsawas commented 1 year ago

https://github.com/ikema77/flutter_auth/blob/0b86b7d22c968fdd363c173abcfbd6dd2510f919/lib/main.dart#L21-L22

Regarding the accessToken, you may have a shared HttpClient object that handles all http requests. This is to make your ChangeNotifiers do not care about adding the Authorization Header in every function because it shouldn't. To achieve this, make your Info class depend on a custom HttpClient object of your creation. Then use this HttpClient object inside your ChangeNotifier to make requests. This custom HttpClient can now intercept any request and add the Authorization Header automatically if it is available.