forked from eatvio/eatvio_app
refactor(token): add token storage, remove hive
This commit is contained in:
@@ -3,11 +3,11 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/presentation/users/subscribers_screen/models/subscribers_model.dart';
|
||||
import 'package:equatable/equatable.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;
|
||||
|
||||
import '/core/app_export.dart';
|
||||
@@ -26,15 +26,13 @@ class SubscribersBloc extends Bloc<SubscribersEvent, SubscribersState> {
|
||||
Emitter<SubscribersState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
if (token == null) {
|
||||
if (!await TokenStorage.haveTokenInStorage()) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await http.get(
|
||||
Uri.parse(baseUrl + '/api/profile/subscribers'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
);
|
||||
print('Got response');
|
||||
|
||||
Reference in New Issue
Block a user