Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Fixed more issues related to login or token expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroRojas committed Jul 11, 2023
1 parent af04556 commit 2964b26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/Helpers/spotify_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ Future<String?> retriveAccessToken() async {
}
await Hive.box('settings')
.put('spotifyTokenExpireAt', currentTime + double.parse(data[2]));
} else {
await Hive.box('settings').put('spotifySigned', false);
accessToken = null;
await Hive.box('settings').put('spotifyAccessToken', null);
if (data[1] != 'null') {
refreshToken = null;
await Hive.box('settings').put('spotifyRefreshToken', null);
}
await Hive.box('settings').put('spotifyTokenExpireAt', 0);
}
}
return accessToken;
Expand All @@ -77,9 +86,10 @@ Future<void> callSpotifyFunction({
});
}
if (accessToken == null && forceSign) {
final spotifyApi = SpotifyApi();
launchUrl(
Uri.parse(
SpotifyApi().requestAuthorization(),
spotifyApi.requestAuthorization(),
),
mode: LaunchMode.externalApplication,
);
Expand All @@ -91,8 +101,7 @@ Future<void> callSpotifyFunction({
final code = link.split('code=')[1];
Hive.box('settings').put('spotifyAppCode', code);
final currentTime = DateTime.now().millisecondsSinceEpoch / 1000;
final List<String> data =
await SpotifyApi().getAccessToken(code: code);
final List<String> data = await spotifyApi.getAccessToken(code: code);
if (data.isNotEmpty) {
await Hive.box('settings').put('spotifyAccessToken', data[0]);
await Hive.box('settings').put('spotifyRefreshToken', data[1]);
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ dependencies:
flutter:
sdk: flutter
flutter_archive: ^5.0.0
flutter_background_service: ^2.4.6
flutter_displaymode: ^0.6.0
# flutter_downloader: ^1.7.1
flutter_localizations:
Expand Down

0 comments on commit 2964b26

Please sign in to comment.