mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not hiding fields

rhyek opened this issue · comments

Is there anything wrong with this configuration?

import mongoose from 'mongoose'
import hidden from 'mongoose-hidden'

const schema = new mongoose.Schema({
  email: {
    type: String,
    unique: true,
  },
  hashedPassword: {
    type: String,
    hide: true,
  },
  firstName: String,
  lastName: String,
  profilePicture: Object,
  isAdmin: Boolean,
  organizations: [{ type: mongoose.Schema.ObjectId, ref: 'Organization' }],
})

schema.plugin(hidden)

export default mongoose.model('User', schema)

Neither toJSON nor toObject are actually hiding hashedPassword.

Using mongodb 3.0.2, mongoose 5.0.6, mongoose-hidden 1.5.3.

Try

schema.plugin(hidden())

The plugin import is a function. Let me know if that helps.

Yup, that works. Missed those parenthesis in the examples :).