We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
How can I hide the password? is there any way to not select the password using typescript-sequelize?
// src/models/user.model.ts import { Table, Column, Model } from 'sequelize-typescript'; import { Exclude } from 'class-transformer'; import { IsNotEmpty } from 'class-validator'; import { IsEmail } from 'class-validator'; @Table export class User extends Model { @Column @IsNotEmpty() name: string; @Column @IsEmail() email: string; @Column @Exclude({ toPlainOnly: true }) password: string; @Column({ type: 'ENUM', values: ['l', 'p'], }) gender: string; }
The text was updated successfully, but these errors were encountered:
I override toJSON
toJSON
toJSON() { const json = super.toJSON(); // Make sure that the password is not included in the response delete json.password; return json; }
Sorry, something went wrong.
You can also use scopes for this
@Table @DefaultScope(() => { exclude: ['password'] }) export class User extends Model {...}
And then, for cases where you need it, you can create a different @Scope() you can find more here https://github.com/sequelize/sequelize-typescript?tab=readme-ov-file#scopes
@Scope()
@Column({ get: () => undefined, }) password: string;
No branches or pull requests
Issue
How can I hide the password? is there any way to not select the password using typescript-sequelize?
Versions
Issue type
Actual behavior
Expected behavior
Steps to reproduce
Related code
The text was updated successfully, but these errors were encountered: