mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
22 lines
650 B
Dart
22 lines
650 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:spotify/spotify.dart';
|
|
import 'package:spotube/models/generated_secrets.dart';
|
|
import 'package:spotube/provider/Auth.dart';
|
|
import 'package:spotube/utils/primitive_utils.dart';
|
|
|
|
final spotifyProvider = Provider<SpotifyApi>((ref) {
|
|
Auth authState = ref.watch(authProvider);
|
|
final anonCred = PrimitiveUtils.getRandomElement(spotifySecrets);
|
|
|
|
if (authState.isAnonymous) {
|
|
return SpotifyApi(
|
|
SpotifyApiCredentials(
|
|
anonCred["clientId"],
|
|
anonCred["clientSecret"],
|
|
),
|
|
);
|
|
}
|
|
|
|
return SpotifyApi.withAccessToken(authState.accessToken!);
|
|
});
|