Steps for concealing a specific field in StrongLoop's outcome

Currently, I am working on a project using strongloop to develop a web service for user login. While my code is functioning properly and producing the desired output, the issue lies in the fact that it does not hide the password.

The result I am receiving is as follows:

{
    "result": [{
        "_id": 2,
        "address": "abc",
        "created_by": 1,
        "created_date": "2016-03-04T00:00:00.000Z",
        "firstname": "Anup",
        "isdeleted": 0,
        "lastname": "Deshpande",
        "mobile_number": "9700128907",
        "oldpassword": "string",
        "profile_picturename": "anup.jpeg",
        "role_id": 1,
        "user_email_id": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81e0eff4f1e5c1e8e5e4e0e4eff5e8f5f8afe2eeec">[email protected]</a>",
        "user_password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
        "user_status": 1
    }]
}

I am looking for a way to either hide or remove the

"user_password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
field.

If anyone can guide me on how to achieve this in a remote method of strongloop, I would greatly appreciate it.

My current remote method code is as follows:

db.collection('users').find({
                user_email_id : par,
                user_password : sha256(par2)
            }).toArray(function(err, result) {

                // var passwordHash = hashPassword(user_password);
                // console.log(passwordHash);
                if (err) {
                    throw err;
                }
                if (result.length > 0) {
                    self.callback(null, result);
                    // db.disconnect();
                } else {
                    self.callback(null, response);
                    // db.disconnect();
                }
            });

In this code, the "result" will provide all details, but I aim to conceal the password from the result.

Thank you in advance.

Answer №1

Give this a try:

{ fields: {propertyName: <true|false>, propertyName: <true|false>, ... } }

The propertyName refers to the property (field) that you want to include or exclude. Use either true or false Boolean literal to specify inclusion or exclusion. Set true to include the property or false to exclude it from results. You can also use 1 for true and 0 for false. By default, queries return all model properties in results. However, if you specify at least one fields filter with a value of true, the query will include only those specified with filters.

Check out this link

Example:
var query = { fields: {password: false} }
Model.find(query, function()
{
});

Alternatively, you can manually remove it in afterremotemethod(), within ctx.result. Check this link for more information

Answer №2

To add a hidden field in your model.json, include the following line: "hidden": ["password", "verificationToken"].

For example:
{
  "name": "User",
  "properties": {
    "realm": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "password": {
      "type": "string",
      "required": true
    },
    "credentials": {
      "type": "object",
      "deprecated": true
    },
    "challenges": {
      "type": "object",
      "deprecated": true
    },
    "email": {
      "type": "string",
      "required": true
    },
    "emailVerified": "boolean",
    "verificationToken": "string",
    "status": "string",
    "created": "date",
    "lastUpdated": "date"
  },
  "options": {
    "caseSensitiveEmail": true
  },
  "hidden": ["password", "verificationToken"],
  "acls": [

  ],
  "relations": {

  }
}

Answer №3

in my experience

// {user_password:0} - to conceal password

db.collection('users').find({
                user_email_id : par,
                user_password : sha256(par2)
            },{user_password:0}).toArray(function(err, result) {

this solution worked perfectly

for more information you can refer to this resource

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Are there any available resources in Node.js or REST API for establishing new user accounts in Office 365?

I recently bought the Office 365 essentials plan and have been able to set up an admin account. However, I am looking to streamline the process of adding new users under this account by utilizing a Node.js or REST API. Despite conducting thorough researc ...

The current situation is not effective; it is causing an error saying "Uncaught TypeError: Cannot read property 'substring' of undefined"

Encountering an error "Uncaught TypeError: Cannot read property 'substring' of undefined" while debugging in Chrome Inspector, with the following code: <script type="text/javascript"> $(function countComments() { var mcount = '/ ...

What steps should I take to make sure that the types of React props are accurately assigned?

Dealing with large datasets in a component can be challenging, but I have found a solution by creating a Proxy wrapper around arrays for repeated operations such as sorting. I am looking to ensure that when the data prop is passed into my component as an ...

User interface design for node.js and jquery web applications

When using node.js for web applications, is there a preferred UI framework to pair with it? Or is this an independent consideration? While jQuery is popular, is jQuery UI the most commonly used UI framework with the jQuery engine? Ar ...

Changing the HTML content of the body before it is loaded and presented in the browser

Is there a way to change the content of a page before the DOM is displayed using JavaScript or jQuery? I have been able to somewhat achieve this by using the following code: jQuery(document).ready(function() { jQuery('body').load( ...

During the process of executing a HTTP GET request, an output of "OPTIONS https://riskassessmentidtypes.px-npe01.com/customer-credit/ 0 ()" was obtained

I am currently engaged in an internal project involving Angular 5. Our team is working on making an HTTP GET call to a URL located within the PCF environment. However, during this process, I encountered the following console message: OPTIONS 0 () Progre ...

Can you explain the concept of a factory function to me?

As I delve into learning Javascript, I have encountered terms like factory functions and constructor functions in the realm of object-oriented programming. Despite my attempts to grasp the distinction between them, I still find myself struggling to fully ...

Troubleshooting problems with the Quora pixel after refreshing the page

Having a strange issue with the Quora pixel integration on Angular. I have added the script in the HTML code as follows: ! function(q, e, v, n, t, s) { if (q.qp) return; n = q.qp = function() { n.qp ? n.qp.apply(n, arguments) : n.queue.push ...

Change a text file into JSON by using key-value pairs or headers along with CSV in Python, JavaScript, or PHP

I have a text file with the following format. I would like to convert it to CSV with headers like in https://i.sstatic.net/WjwC7.png or as JSON key-value pairs. Any guidance would be greatly appreciated. ...

Access the data within a jsonArray using Cypress

I'm dealing with a test.json file that contains a jsonArray [{ "EMAIL": "email_1", "FIRST_NAME": "Daniel" }, [{ "EMAIL": "email_2", "FIRST_NAME": "John" }] ] I'm trying to figure out how to use cypre ...

React project automatically refreshing when local server generates new files

I have developed a tool for developers that allows them to retrieve device data from a database for a specific time period, generate plots using matplotlib, save the plots locally, and display them on a webpage. The frontend is built using create-react-app ...

"Encountering a glitch involving Vue.js 3, Pinia, and a centralized store

While using Pinia in a Vue.js 3 project, I encountered an issue. The problem arises when I attempt to load constant JSON structures from my backend using the file src/store/constants.store.ts // @ts-check import { defineStore } from "pinia" impor ...

Error with Husky during precommit:

I've upgraded to the latest version of yarn and now I'm setting up Husky in my project. Here is the content from .huskyrc.json: { "hooks": { "pre-commit": "lint-staged", "pre-push": "npm run ...

A more intelligent approach for generating JSON responses using Mysql

Here is the code I have on my server side using Node.js: var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'SOMEUSER', password: 'SOMEPASSWD', database: 'SOMED ...

When a two-sided object is rotated on the y-axis in THREE.js, the graphic vanishes into

class Game extends backbone.View constructor: -> @scene = new THREE.Scene() @camera = new THREE.PerspectiveCamera 75, window.innerWidth/window.innerHeight, 1, 100000 @camera.position.z = 300 @scene.add @camera ...

The performance of Javascript versus Java on PlayN varies significantly

After building the PlayN project and running the Java version, I noticed that its behavior is not consistent with the HTML version. I created a board game that utilizes a customized Minimax algorithm for its AI, which includes a search tree and evaluation ...

An error is triggered by serializing a TinyBox POST form into an Array

When I implemented the code below, it performed as anticipated: TINY.box.show({url:target, post:$("form[name='currentSearch']").serialize(), width:650, mask:true, close:true, maskid:'boxMask', boxid:'popupBox', openjs:funct ...

Next JS is trying to access a JSON file that does not exist

After setting up a route "/es/servicios" and configuring it in next.config.js: module.exports = { async redirects() { return [ { source: '/', destination: '/es', ...

"Ensure only one checkbox is selected at a time by unchecking the previous

Hi, I'm facing two issues with the code below. The first problem is that when I select checkbox number 3, it automatically selects number 2 as well. I only want this to happen if I manually check it (similar to checkbox number 2). The second issue i ...

Issues with rendering in Next.jsORErrors encountered during rendering

Encountering errors while attempting to build my page using "Yarn Build" Automatically optimizing pages ... Error occurred prerendering page "/design/des". More details: https://err.sh/next.js/prerender-error: Error: Cannot find module './des.md&apos ...