mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 11:57:54 +00:00
Added Error handling
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.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/helpers/decode_base64.dart';
|
||||
|
||||
part 'auth_state.dart';
|
||||
@@ -47,17 +48,23 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
password: passwordController.text,
|
||||
);
|
||||
|
||||
emit(AuthSuccess());
|
||||
if (token.accessTokenIsNotEmpty) {
|
||||
final parts = token.accessToken.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw Exception('invalid access token');
|
||||
}
|
||||
final payload = decodeBase64(parts[1]);
|
||||
final payloadMap = json.decode(payload); //Map dictionary
|
||||
user = UserModel.fromToken(payloadMap);
|
||||
emit(AuthSuccess());
|
||||
} else {
|
||||
emit(AuthError('Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is ServerFailure) {
|
||||
emit(AuthError(e.errMessage));
|
||||
}
|
||||
emit(AuthError(e.toString()));
|
||||
}
|
||||
|
||||
final parts = token.accessToken.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw Exception('invalid access token');
|
||||
}
|
||||
final payload = decodeBase64(parts[1]);
|
||||
final payloadMap = json.decode(payload); //Map dictionary
|
||||
user = UserModel.fromToken(payloadMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ class Token {
|
||||
: accessToken = '',
|
||||
refreshToken = '';
|
||||
|
||||
bool get accessTokenIsNotEmpty => accessToken.isNotEmpty;
|
||||
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
|
||||
Reference in New Issue
Block a user