[Change Pass] 4. revisi pemberian token ke BE

This commit is contained in:
Stephen
2024-01-21 13:05:58 +07:00
parent 6b28794577
commit d3e455c371
4 changed files with 22 additions and 6 deletions

View File

@@ -62,11 +62,13 @@ class AuthRepository extends BaseRepository {
Future<String> changePassword({
required String userID,
required String token,
required String tokenx,
required String oldPassword,
required String newPassword,
required String confirmPassword,
}) async {
final param = {
"tokenx": tokenx,
"token": token,
"M_UserID": userID,
"old_password": oldPassword,

View File

@@ -40,7 +40,6 @@ class ChangePasswordStateDone extends ChangePasswordState {
}) : super(DateTime.now());
}
//notifier
class ChangePasswordNotifier extends StateNotifier<ChangePasswordState> {
final Ref ref;
@@ -51,16 +50,21 @@ class ChangePasswordNotifier extends StateNotifier<ChangePasswordState> {
void postChangePassword({
required String userID,
required String userToken,
required String userTokenx,
required String oldPassword,
required String newPassword,
required String confirmPassword,
}) async {
}) async {
try {
state = ChangePasswordStateLoading();
final dio = ref.read(dioProvider);
final resp =
await AuthRepository(dio: dio).changePassword(userID: userID,token: userToken, oldPassword: oldPassword, newPassword: newPassword, confirmPassword: confirmPassword);
final resp = await AuthRepository(dio: dio).changePassword(
userID: userID,
tokenx: userTokenx,
token: userToken,
oldPassword: oldPassword,
newPassword: newPassword,
confirmPassword: confirmPassword);
state = ChangePasswordStateDone(model: resp);
} catch (e) {
if (e is BaseRepositoryException) {
@@ -76,4 +80,4 @@ class ChangePasswordNotifier extends StateNotifier<ChangePasswordState> {
final ChangePasswordProvider =
StateNotifierProvider<ChangePasswordNotifier, ChangePasswordState>(
(ref) => ChangePasswordNotifier(ref: ref),
);
);

View File

@@ -23,6 +23,7 @@ class ChangePasswordScreen extends HookConsumerWidget {
//menampung user token jika ada
final userToken = ref.read(currentUserProvider)?.token ?? "";
final userID = ref.read(currentUserProvider)?.model.M_UserID ?? "0";
final tokenx = ref.read(currentUserProvider)?.token ?? "";
final isLoading = useState(false);
final obscureText = useState<bool>(true);
@@ -357,6 +358,7 @@ class ChangePasswordScreen extends HookConsumerWidget {
ref
.read(ChangePasswordProvider.notifier)
.postChangePassword(
userTokenx: tokenx,
userToken: userToken,
userID: userID,
oldPassword: ctrlOldPassword.text,

View File

@@ -901,6 +901,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.17"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
whatsapp_share:
dependency: "direct main"
description: