Skip to content

Commit

Permalink
fix(#58): atualização do usuario e logout
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielCostaDeOliveira committed Jan 26, 2025
1 parent 1f10097 commit 8ed93bb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ class AuthRepository {
_userCache = user;
return user;
} catch (e) {
throw Exception('Erro ao obter o usuário');
throw Exception(e);
}
}
}

Future<void> clearUser() async {
_userCache = null;
StorageValue.getInstance().setJsonUser(null);
await GetIt.instance<AuthService>().refreshToken();
}
}
3 changes: 2 additions & 1 deletion lib/core/network/token_manager/service/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class AuthService {
}

Future<UserModel> getUser() async {
Log.d("get user");
String? json = await StorageValue.getInstance().getJsonUser();

if (json != null) {
Expand All @@ -46,6 +45,8 @@ class AuthService {

Map<String, dynamic> json = jsonDecode(response.toString());

if (json['userPayload'] == null) Log.e('user payload is null');

UserModel user = UserModel.fromMap(json['userPayload']!);

await StorageValue.getInstance().setJsonUser(user.toJson());
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/edit_delete_user/view/edit_delete_user_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:aranduapp/core/log/log.dart';
import 'package:aranduapp/ui/edit_delete_user/viewmode/edit_delte_user_viewmodel.dart';
import 'package:aranduapp/ui/login/view/login_view.dart';
import 'package:aranduapp/ui/shared/command_button.dart';
Expand Down Expand Up @@ -51,6 +52,7 @@ class EditDeleteUserScreen extends StatelessWidget {
);
},
onErrorCallback: (e) {
Log.e(e);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Não foi possível apagar a conta')),
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/edit_profile/viewmodel/edit_profile_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:aranduapp/core/network/token_manager/model/user_model.dart';
import 'package:aranduapp/core/network/token_manager/repository/auth_repository.dart';
import 'package:aranduapp/core/network/token_manager/service/auth_service.dart';
import 'package:aranduapp/core/state/command.dart';
import 'package:aranduapp/ui/edit_profile/model/edit_profile_request.dart';
import 'package:aranduapp/ui/edit_profile/service/edit_profile_service.dart';
Expand All @@ -22,6 +23,7 @@ class EditProfileViewModel extends ChangeNotifier {
await GetIt.instance<EditProfileService>().edit(request);

await GetIt.instance<AuthRepository>().clearUser();
await GetIt.instance<AuthService>().refreshToken();
return Result.value(null);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/ui/profile/view/profile_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class Profile extends StatelessWidget {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const EditProfile()),
);
).then((result) {
viewModel.getUserCommand.execute();
});
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
Expand Down
1 change: 0 additions & 1 deletion lib/ui/profile/viewmodel/profile_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ProfileViewModel extends ChangeNotifier {

Future<Result<void>> logout() async {
await StorageValue.getInstance().clear();
await GetIt.instance<AuthRepository>().clearUser();

Log.d("Usuário deslogado com sucesso.");
return Result.value(null);
Expand Down

0 comments on commit 8ed93bb

Please sign in to comment.