mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-24 14:37:56 +00:00
Fixed logout issue
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
|
||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
||||
@@ -13,10 +11,7 @@ import 'package:syncrow_app/services/api/authentication_api.dart';
|
||||
part 'auth_state.dart';
|
||||
|
||||
class AuthCubit extends Cubit<AuthState> {
|
||||
AuthCubit() : super(AuthInitial()) {
|
||||
getTokenAndValidate();
|
||||
}
|
||||
|
||||
AuthCubit() : super(AuthInitial());
|
||||
static AuthCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
final TextEditingController emailController = TextEditingController();
|
||||
@@ -108,8 +103,7 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
if (token.accessTokenIsNotEmpty) {
|
||||
debugPrint('token: ${token.accessToken}');
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.write(
|
||||
key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||
await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||
|
||||
const FlutterSecureStorage().write(
|
||||
key: UserModel.userUuidKey,
|
||||
@@ -129,9 +123,10 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
try {
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.delete(key: Token.loginAccessTokenKey);
|
||||
NavigationService.navigatorKey.currentState!
|
||||
.popAndPushNamed(Routes.authLogin);
|
||||
emit(AuthLogoutSuccess());
|
||||
NavigationService.navigatorKey.currentState!.pushNamedAndRemoveUntil(
|
||||
Routes.splash,
|
||||
(Route route) => false,
|
||||
);
|
||||
} catch (failure) {
|
||||
emit(AuthLogoutError(message: failure.toString()));
|
||||
return;
|
||||
@@ -140,8 +135,7 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
|
||||
getTokenAndValidate() async {
|
||||
emit(AuthTokenLoading());
|
||||
final value =
|
||||
await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
|
||||
final value = await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
|
||||
|
||||
if (value == null || value.isEmpty) {
|
||||
emit(AuthTokenError(message: "Token not found"));
|
||||
|
||||
Reference in New Issue
Block a user