Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projected fields are returned not decrypted #110

Open
Sammi89 opened this issue Oct 21, 2024 · 4 comments
Open

Projected fields are returned not decrypted #110

Sammi89 opened this issue Oct 21, 2024 · 4 comments
Assignees

Comments

@Sammi89
Copy link

Sammi89 commented Oct 21, 2024

Hi guys, I'm using version 7.0.1 of mongoose-field-encryption. Trying to run a simple find query projecting some of the encryoted fields, the query results data are not decrypted automatically. Is this a desired behavior or an issue?
Thanks a lot.

@wheresvic
Copy link
Owner

@Sammi89 Can you provide some sample code please?

The plugin is quite well tested and you can see samples for plugin usage in the tests:

https://github.com/wheresvic/mongoose-field-encryption/blob/master/test/test-basic-usage.js

@Sammi89
Copy link
Author

Sammi89 commented Oct 21, 2024

Sure! I'm working with NestJS. I'll write you an example:

@Schema({ timestamps: true })
export class User extends SoftDeletedContent<User> {
  @Prop({
    required: true,
    trim: true,
    maxLength: 50,
  })
  firstName: string;

  @Prop({
    required: true,
    trim: true,
    maxLength: 50,
  })
  lastName: string;

  @Prop({
    required: true,
    trim: true,
    maxLength: 255,
  })
  email: string;
}

export const UserSchema = SchemaFactory.createForClass(User);

UserSchema.plugin(fieldEncryption, {
  fields: ['email', 'firstName', 'lastName'],
  secret: config.secret,
  saltGenerator: config.saltGenerator,
});

const UserModel = model('User', UserSchema);
const users = await UserModel.find({}, [], { projection: { firstName: 1, lastName: 1 } })

@wheresvic
Copy link
Owner

Ah I see what you mean - you are using the projection feature.

Unfortunately, this plugin does not support this feature :(.

@Sammi89
Copy link
Author

Sammi89 commented Oct 21, 2024

Ok, thanks anyway for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants