You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might not be specific to all of next-auth package as a whole, but there's one nuance I noticed.
const{ data }=useSession();
The type of data object here is Session | null. But this is not true. I'm not sure how next-auth communicates the values of session through its useSession hook, but the expectation might've been to communicate null as the value for cases when session is not found.
But there's a gotcha with this practice in javascript, there's a value other than null which is used to communicate absence of a value, it is undefined. Perhaps the expectation of next-auth team for developers was to treat the values as falsy values and compare them accordingly instead of comparing the literal values(comparing to null here).
When we're writing UI logic, we might compare the session object explicitly with null instead of being a falsy value, i.e., both null and undefined. Since, the type of session object next-auth specifies is Session | null, the developers might expect it to never be undefined which isn't the case.
It is a nuanced case but I think explicitly typing out the session object as Session | null | undefined would communicate the types better.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
It might not be specific to all of next-auth package as a whole, but there's one nuance I noticed.
The type of
data
object here isSession | null
. But this is not true. I'm not sure how next-auth communicates the values of session through its useSession hook, but the expectation might've been to communicatenull
as the value for cases when session is not found.But there's a gotcha with this practice in javascript, there's a value other than
null
which is used to communicate absence of a value, it isundefined
. Perhaps the expectation of next-auth team for developers was to treat the values as falsy values and compare them accordingly instead of comparing the literal values(comparing tonull
here).When we're writing UI logic, we might compare the session object explicitly with
null
instead of being a falsy value, i.e., bothnull
andundefined
. Since, the type of session object next-auth specifies isSession | null
, the developers might expect it to never beundefined
which isn't the case.It is a nuanced case but I think explicitly typing out the session object as
Session | null | undefined
would communicate the types better.Beta Was this translation helpful? Give feedback.
All reactions