#nextjs typescript
1 messages · Page 1 of 1 (latest)
The error you're encountering is due to TypeScript's strict type checking. The compare function expects a string as an argument, but it's possible that user.password could be null.
To fix this, you should add a check to ensure user.password is not null before calling the compare function. Here's how you can do it:
if (!user.password) {
throw Error("No password found for this user!");
}
authPassword = await compare(password, user.password);
The second error is because you're trying to assign a Promise to a boolean variable. The compare function is asynchronous and returns a Promise, not a boolean. You should await the Promise to get the boolean result:
authPassword = await compare(password, user.password);
If you're still encountering issues, make sure you're using a compatible version of TypeScript. As per the Next.js documentation (https://nextjs.org/docs/app/building-your-application/configuring/typescript), you should be using TypeScript 5.1.3 or higher and @types/react 18.2.8 or higher.