Start writing the web app
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <allanger@posteo.com>
This commit was merged in pull request #5.
This commit is contained in:
42
lib/core/tokens/data/token_storage_repository.dart
Normal file
42
lib/core/tokens/data/token_storage_repository.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
const accessTokenKey = "access_token";
|
||||
const refreshTokenKey = "refresh_token";
|
||||
|
||||
final tokenStorageRepositoryProvider = Provider<TokenStorageRepository>((ref) {
|
||||
return TokenStorageRepository();
|
||||
});
|
||||
|
||||
// Secure storage backend for storing tokens in the browser
|
||||
class TokenStorageRepository {
|
||||
static const _storage = FlutterSecureStorage();
|
||||
TokenStorageRepository();
|
||||
|
||||
// Store the refresh token in the storage
|
||||
Future<void> storeRefreshToken(String token) async {
|
||||
await _storage.write(key: refreshTokenKey, value: token);
|
||||
}
|
||||
|
||||
// Store the access token in the storage
|
||||
Future<void> storeAccessToken(String token) async {
|
||||
await _storage.write(key: accessTokenKey, value: token);
|
||||
}
|
||||
|
||||
// Get the acccess token from the storage
|
||||
Future<String?> getAccessToken() async {
|
||||
final token = await _storage.read(key: accessTokenKey);
|
||||
return token;
|
||||
}
|
||||
|
||||
// Get the refresh token from the storage
|
||||
Future<String?> getRefreshToken() async {
|
||||
final token = await _storage.read(key: refreshTokenKey);
|
||||
return token;
|
||||
}
|
||||
|
||||
Future<void> clearStorage() async {
|
||||
await _storage.delete(key: refreshTokenKey);
|
||||
await _storage.delete(key: accessTokenKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user