Skip to content

How to add a base header #139

Answered by oarshad
booozz asked this question in Q&A
Discussion options

You must be logged in to vote

You can set that in your adapter like so:

mixin ApplicationAdapter<T extends DataModel<T>> on RemoteAdapter<T> {
  @override
  String get baseUrl => "http://localhost:8080/api/v1/";

  @override
  FutureOr<Map<String, String>> get defaultHeaders async {
    final token = await read(tokenProvider.future);
    if (token == null) {
      return await super.defaultHeaders;
    } else {
      return await super.defaultHeaders
        ..addAll({'Authorization': 'Bearer $token'});
    }
  }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by frank06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants