forked from eatvio/eatvio_app
feat(chat): bubbles
This commit is contained in:
32
lib/core/token_storage.dart
Normal file
32
lib/core/token_storage.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
abstract class TokenStorage {
|
||||
static addTokenToDioHeader(String token) {
|
||||
sl<Dio>().options.headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
|
||||
static haveTokenInStorage() async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
return false;
|
||||
} else {
|
||||
addTokenToDioHeader(token);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static getTokenFromStorage() async => await Hive.openBox('token')
|
||||
..get('token');
|
||||
|
||||
static saveTokenInStorage(String token) async {
|
||||
await Hive.openBox('token')
|
||||
..put('token', token);
|
||||
addTokenToDioHeader(token);
|
||||
}
|
||||
|
||||
static removeTokenInStorage(String token) async => await Hive.openBox('token')
|
||||
..delete('token');
|
||||
}
|
||||
Reference in New Issue
Block a user