Files
eatvio_app/lib/core/token_storage.dart
2025-08-19 14:24:14 +03:00

47 lines
1.3 KiB
Dart

import 'package:shared_preferences/shared_preferences.dart';
import 'locator_service.dart';
abstract class TokenStorage {
static bool haveTokenInStorage() {
try {
if (sl<SharedPreferences>().getString('token') == null) {
return false;
} else {
return true;
}
} catch (e) {
return false;
}
}
static String? getTokenFromStorage() => sl<SharedPreferences>().getString('token');
static Future<void> saveTokenInStorage(String token) async {
await sl<SharedPreferences>().setString('token', token);
}
static Future<void> removeTokenInStorage() async => (await sl<SharedPreferences>().remove('token'));
}
abstract class SocketIdStorage {
static bool haveSocketIdInStorage() {
try {
if (sl<SharedPreferences>().getString('socketId') == null) {
return false;
} else {
return true;
}
} catch (e) {
return false;
}
}
static String? getSocketIdFromStorage() => sl<SharedPreferences>().getString('socketId');
static Future<void> saveSocketIdInStorage(String socketId) async {
await sl<SharedPreferences>().setString('socketId', socketId);
}
static Future<void> removeSocketIdInStorage() async => (await sl<SharedPreferences>().remove('socketId'));
}