Can't get the user info from const { getUser } = getKindeServerSession();
I must be totally braindead but I'm just trying to get the information about the user in this way. Using next.js.
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
Property 'email' does not exist on type 'Promise<KindeUser | null>'. Isn't it supposed to be an object? I'm logged in and everthing.
I'm every writing exactly as Josh tried coding does
18 Replies
Hey, I answered in #π¬βgeneral but I'll answer here too.
You need to make your Page function an async function and to await your getUser call:
thank you so much sir, of course. How could I have missed this. I spent 3 hours on this. HGHAHAHHA
getUser
is an asynchronous function which means in order to use the value it returns (KindeUser | null
), we need to wait for the execution to finish.
There's multiple ways we can do this, but the best is probably to await it
No worries πoh so before the data was actually there it was just a promise
Yes exactly. The
Promise
object represents the eventual completion of a taskIts strange it worked for Josh tried coding in his popular video "Build a Complete SaaS Platform with Next.js 13, React, Prisma, tRPC, Tailwind | Full Course 2023".
He didnt have async.
When we run what you had:
const user = getUser();
JavaScript calls the getUser() function and then immediately continues. This returns a Promise as we can't guarantee the getUser function is finished, being an asynchronous task.
When we write the await
keyword, we're telling JavaScript to wait at that point until the getUser() function is finishedI learn new things every day. Thanks.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
MDN Web Docs
Promise - JavaScript | MDN
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
MDN Web Docs
await - JavaScript | MDN
The await operator is used to wait for a Promise and get its fulfillment value. It can only be used inside an async function or at the top level of a module.
Here's some further reading if you're interested, they're important concepts, especially now with RSC
Yeah I know in theory what asyncronious js is.
What is RSC?
Thanks btw for the extended explanations. Really appreciated.
React Server Components (next.js app router)
oh yes! ok!
I've said for 5 years I'm not going to become a decent developer its just something life put me to do π but still I learn more everyday. haha.
It's actually very fun once you start grasping the concepts a bit better.
And kinde is very good for me, because all hackers from Russia are trying to break all Swedish systems now I dont have to worry about the auth security lol
I agree π
Btw I see the josh tried coding video you're talking about, curious that he's not using async and it's working for him... Maybe one of the Kinde guys can answer that for us
Next time something like this happens I have more wisdom.
I agree pretty strange indeed.
Ah yep, in the Joshtriedcoding video it may have been a previous version of the sdk π
Yes, the API was updated to be async I believe after JostTriedCoding video.
There we go, that makes sense. Thanks for the clarification π