My database has a table like this :
id | rt |
---|---|
1 | value1 (hashed by argon) |
2 | value2 (hashed by argon) |
Which I want a record that match some value with hashed rt. somting like this :
SELECT * FROM TABLE WHERE (argon.verify(rt,"some value"))
How can I get something like this in TypeORM ?
It seems that there is no solution at the database level. The problem can be solved as follows :
async findOneByUserAndRefreshToken(
userId: number,
refreshToken: string,
): Promise<Device | undefined> {
const devices = await this.repo.find({
where: {
rtExpiresIn: MoreThan(new Date()),
user: { id: userId },
},
});
const device = devices.find((device) =>
argon.verify(device.refreshToken, refreshToken),
);
return device;
}