forked from eatvio/eatvio_app
refactor(token): add token storage, remove hive
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart';
|
||||
import 'package:eatvio_app/widgets/custom_hyper_switch.dart';
|
||||
import 'package:eatvio_app/widgets/custom_hypo_switch.dart';
|
||||
@@ -8,7 +9,6 @@ import 'package:eatvio_app/widgets/next_step_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
@@ -384,8 +384,7 @@ class _ExpandableListState extends State<ExpandableList> {
|
||||
}
|
||||
|
||||
Future<String?> _getTokenFromBox() async {
|
||||
final box = await Hive.openBox('token');
|
||||
return box.get('token');
|
||||
return await TokenStorage.getTokenFromStorage();
|
||||
}
|
||||
|
||||
String _buildApiUrl() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/widgets/custom_navigation_menu_item.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CustomNavigationMenu extends StatelessWidget {
|
||||
@@ -61,8 +61,7 @@ class CustomNavigationMenu extends StatelessWidget {
|
||||
|
||||
_onTapLogout(BuildContext context) {
|
||||
return () async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
final token = await TokenStorage.getTokenFromStorage();
|
||||
final response = await http.post(
|
||||
Uri.parse(baseUrl + '/api/profile/logout'),
|
||||
headers: {
|
||||
@@ -71,8 +70,7 @@ _onTapLogout(BuildContext context) {
|
||||
);
|
||||
|
||||
if (response.statusCode == 204) {
|
||||
print(response.statusCode);
|
||||
box.delete('token'); // Удаляем токен из Hive
|
||||
await TokenStorage.removeTokenInStorage();
|
||||
GoRouter.of(context).go('/auth-screen');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user