Skip to content

Commit

Permalink
Improve DSAuthService usability
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Amaro committed Jul 17, 2023
1 parent ad11108 commit 8843fcc
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lib/src/services/ds_auth.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@ abstract class DSAuthService {
static String? _token;
static String? get token => _token;

static void init({
required final String userAccessToken,
static void setUser({
required final String accessToken,
}) {
assert(userAccessToken.isNotEmpty, 'The token must not be empty.');
assert(_token == null, 'The DSAuthService was already initialized.');

_token = userAccessToken;
_token = accessToken;
}

static void dispose() {
static void clearUser() {
_token = null;
}

static Map<String, String> get httpHeaders {
assert(
token?.isNotEmpty ?? false,
'The DSAuthService must be initialized.',
);

return {
'Authorization': 'Key $token',
};
}
static Map<String, String> get httpHeaders => token?.isNotEmpty ?? false
? {
'Authorization': 'Key $token',
}
: const {};
}

0 comments on commit 8843fcc

Please sign in to comment.