This seems like such a simple question to answer, but finding an answer for this seems impossible.
I am building a password reset feature for a backend application with Express and Typescript. I am using Postgres for the database and Typeorm for data manipulation. I have a User entity with these two columns in my database:
@Column({
unique: true,
nullable: true,
})
resetPasswordToken!: string;
@Column({ nullable: true, type: 'timestamp with time zone' })
resetPasswordExpiresAt!: Date;
When a user requests a password reset token the resetPasswordToken and resetPasswordExpiresAt fields get both filled with the desired values. With the token that was sent to the user's e-mail address, the user can reset his/her password. After the user's password is reset, I want to clear these two fields by setting them to null:
user.resetPasswordToken = null;
user.resetPasswordExpiresAt = null;
user.save()
But if I do this Typescript complains about the two lines where I assign the null value:
Type 'null' is not assignable to type 'string'.
and
Type 'null' is not assignable to type 'Date'.
If I change the columns in my entity to accept null like below, the errors disappear:
resetPasswordToken!: string | null;
...
resetPasswordExpiresAt!: Date | null;
But when I start my Express application I get the following error when Typeorm tries to connect to my database:
Data type "Object" in "User.resetPasswordToken" is not supported by "postgres" database.
How do I set these fields to null?