-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better typing of UserSession #38
Comments
Thanks for your issue @Gerbuuun I do like having the |
Can a TS expert please help with this 😄 . I make the mistake when using the composable all the time because I am not sure of the type of the different properties. I remember using the library for the first time. It took me way too long to figure out that the |
@atinux I have created a PR that fixes the problem. I also just realized that someone else has submitted a PR with a fix already. (I do prefer my solution though) Hope we can merge this soon :)
|
My problem
It has been bugging me for a while that the types of this module do not work at all.
Lets say this is your
auth.d.ts
:On the client-side, all properties of the
useUserSession
composable are of typeany
(only in the playground it works)On the server-side,
UserSession
is defined except for theuser
object.Its type will always be
{} | undefined
regardless of what is specified in theauth.d.ts
(see issue #31 )And when checking for a session using
requireUserSession
the returneduser
object is still possiblyundefined
even though we just checked and required it to not be.I have been tinkering and came up with the following:
Instead of looking for a specific property in the session data (
user
in this case), we check if there are any properties at all.This way you can define anything in the
UserSession
interface and the type works (this uses the playground'sauth.d.ts
)On the client-side I made the following changes:
loggedIn
is now computed based on wether there exist properties on the session objectuser
getter as this property is no longer defined but now the typing is at least correct.I would like to hear feedback from you guys
The text was updated successfully, but these errors were encountered: