mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 23:44:53 +00:00
Modified Devices Pages
This commit is contained in:
@ -2,11 +2,13 @@ import 'package:dio/dio.dart';
|
||||
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';
|
||||
import 'package:syncrow_app/services/api/authentication_api.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
part 'auth_state.dart';
|
||||
|
||||
@ -50,7 +52,10 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
);
|
||||
|
||||
if (token.accessTokenIsNotEmpty) {
|
||||
//Map dictionary
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.write(
|
||||
key: Constants.tokenAccessKey, value: token.accessToken);
|
||||
|
||||
user = UserModel.fromToken(token);
|
||||
emit(AuthSuccess());
|
||||
} else {
|
||||
@ -60,4 +65,15 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
throw ServerFailure.fromDioError(e);
|
||||
}
|
||||
}
|
||||
|
||||
logout() async {
|
||||
emit(AuthLoading());
|
||||
try {
|
||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||
await storage.delete(key: Constants.tokenAccessKey);
|
||||
emit(AuthLoggedOut());
|
||||
} on DioException catch (e) {
|
||||
throw ServerFailure.fromDioError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user