I’m building a project in Node Js & Express & TypeScrypt and i’m encountering a weird problem when i try to retrieve the credentials of an user by email. The query cannot find or distinguish if there is any valid credentials only returns an empty array always. When i retrieve the whole collection and filter it with Ts it works as expected. Anyone has any idea why this is not working as intended?
This is how the client makes the query
async query(query: string , values : any[]) {
if (!this._instance) {
throw Error("PostGreClient instance is null");
}
if (!query) {
throw Error("Query is empty");
}
// Log the query and the values to see what is being executed
console.log("Executing query:", query);
console.log("With parameters:", values);
const obj = {
text : query,
values : values
}
return await this._instance.query(obj);
}
async getCredentialsbyEmail(email: string): Promise<UserCredentials | null> {
try{
this._debugListener("Retrieving credentials for email : " , email)
const result = await this._client.query(`SELECT * from user_credentials WHERE email =$1` ,[email])
const allCredentials = await this.getAllUserCredentials()
const target = allCredentials.find((c)=> {
return c.email === email
})
console.log("Existing Credentials : " + JSON.stringify(allCredentials))
this._debugListener("Current Result : " , result.rows)
console.log("Expected Result = " , target)
if(!result.rowCount || result.rowCount === 0 ){
return null
}
else if(result.rowCount >1){
throw Error("Too many accounts linked to this email : " + email)
}
const credentials = result.rows[0].map((obj : any) => {
return new UserCredentials(
obj.uid,
obj.userUid,
obj.hashed_password,
obj.email
)
})
return credentials
}catch(e){
console.log(e)
if(e instanceof Error){
this._errorListener(e.message)
}
return null
}
}