changePassword method

  1. @override
FutureOr<PassedHttpEntity> changePassword(
  1. RequestHolder request,
  2. ResponseHolder response,
  3. Map<String, dynamic> pathArgs
)
override

Implementation

@override
FutureOr<PassedHttpEntity> changePassword(
  RequestHolder request,
  ResponseHolder response,
  Map<String, dynamic> pathArgs,
) {
  return _wrapper(request, response, pathArgs, () async {
    var body = await request.readAsJson();
    String? id = request.context[ContextFields.userId];
    String? oldPassword = body[BodyFields.oldPassword];
    String? newPassword = body[BodyFields.newPassword];
    if (id == null || oldPassword == null || newPassword == null) {
      throw RequestBodyError(
          'user not logged in or (oldPassword or newPassword are empty)');
    }

    await authService.changePassword(
      id,
      oldPassword: oldPassword,
      newPassword: newPassword,
    );
    return SendResponse.sendDataToUser(response, 'password changed!');
  });
}