Skip to content

Commit

Permalink
fix: token not saving on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricCookie committed Apr 22, 2024
1 parent 97afcea commit ace875e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 103 deletions.
7 changes: 5 additions & 2 deletions lib/src/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class AuthService extends ChangeNotifier {
if (await _shouldRefresh) {
await _refreshAccessToken();
}

return _storage.read(key: _prefsAccessToken);
}

Expand All @@ -84,7 +83,6 @@ class AuthService extends ChangeNotifier {
/// Return a map of claims in the id token
Future<Map<String, dynamic>?> get idClaims async {
final token = await idToken;

return token != null ? getTokenPayload(token) : null;
}

Expand Down Expand Up @@ -125,7 +123,10 @@ class AuthService extends ChangeNotifier {

// Persist all tokens in a TokenResponse
Future<void> _saveTokens(OAuthTokenResult response) async {
await _storage.delete(key: _prefsAccessToken);
await _storage.delete(key: _prefsAccessTokenExpiry);
await _storage.write(key: _prefsAccessToken, value: response.accessToken);

await _storage.write(
key: _prefsAccessTokenExpiry,
value: DateTime.now()
Expand All @@ -134,13 +135,15 @@ class AuthService extends ChangeNotifier {
);

if (response.refreshToken != null) {
await _storage.delete(key: _prefsRefreshToken);
await _storage.write(
key: _prefsRefreshToken,
value: response.refreshToken,
);
}

if (response.idToken != null) {
await _storage.delete(key: _prefsIdToken);
await _storage.write(key: _prefsIdToken, value: response.idToken);
}
}
Expand Down
Loading

0 comments on commit ace875e

Please sign in to comment.