Type Promise not asignable to type Awaitable

What am I doing wrong here and how can I fix it?
6 Replies
Morraez
Morraez2y ago
Can you give some more context
Fervore
FervoreOP2y ago
Sure, this is not really an error, the function works just fine but vscode is screaming at me. The db is in mysql, this query just looks for the user using the email and stores it in the next-auth session which uses jwt strategy and a credentials provider. logging the user returns the user correctly and if it doesn't find it, it ends up beign null but for some reason whenever I try to write a return user, it gives me that vscode error. As far as I know prisma.findUnique returns a js object after the promise resolves or null if it doesn't find it. It stops screaming at me if I return a hardcoded object. My guess is that maybe authorize expects an Awaitable object instead of just a promise? I wouldn't know how to debug it either since ts is pretty new for me and I'm a bit lost. Also the project is built with t3 app and it's like the first thing that I'm doing on it so there's like nothing else in the app.
Alejo
Alejo2y ago
Can you scroll further down on the error message?
Fervore
FervoreOP2y ago
@Alejo
Alejo
Alejo2y ago
Hm, at a glance it would seem that name in the prisma schema is nullable, whereas the function expects the return type of the function to be
{
id: string;
name: string;
email: string | null;
}
{
id: string;
name: string;
email: string | null;
}
but your function is returning
{
id: string;
name: string | null;
email: string | null;
}
{
id: string;
name: string | null;
email: string | null;
}
You'd need to either provide a default value to user.name before returning it and making sure Typescript understands that that value is not null, you can do that by doing something like
return user ? { ...user, name: user.name ? user.name : "" } : null
return user ? { ...user, name: user.name ? user.name : "" } : null
Alternatively the other option is modifying your prisma schema to make name a required field for users
Fervore
FervoreOP2y ago
I get it now, thanks!
Want results from more Discord servers?
Add your server