How can I verify a hash?

I want to run a function export async function findUserByApiKey(apikey: string) { return ( await db .select() .from(user) .where(eq(await argon2.verify(user.apiKey, apikey), true)) )?.[0] } else { return null; } } I want to compare the user.apiKey column with the input, but execute the verify function as an equal? is this approach correct? I can't actually run this, as user.apiKey is a drizzle column, but how would I go about running this verify function?
2 Replies
ff15 open top
ff15 open topOP12mo ago
i'm guessing this would be really computationally inefficient, guess it would be better to store the associated user id with the hash, lookup by the user id, the verify the hash after it has been found?
Angelelz
Angelelz12mo ago
In the code you showed, you are mixing up javascript code and sql code. This is not how you are supposed to use it. You async function verify run in javascript and you want to pass it to a query that runs in sql. You are also attempting to use a column, I'm surprised the compiler is not yelling at you
Want results from more Discord servers?
Add your server