setToken static method
Sets the Bearer token for all subsequent requests.
Persists token in SharedPrefsHelper so that _mergeHeaders — the
single injection point — always reads the authoritative value.
Notifies any registered token listeners after persisting.
If null is passed, resetToken is called instead.
await BaseApi.setToken(loginResponse.token);
Implementation
static Future<void> setToken(String? token) async {
if (token == null) {
await resetToken();
return;
}
await SharedPrefsHelper.setAuthToken(token);
for (final fn in List.of(_tokenListeners)) {
fn(token);
}
}