Skip to content
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

fix: narrowed session type passed to fetch session hook #71

Merged
merged 3 commits into from
Apr 3, 2024

Conversation

Gerbuuun
Copy link
Contributor

The return value of requireUserSession is guaranteed to have the user component defined.
Previously, the return type was changed to reflect that fact but the session type passed to the fetch hook was not.
(It was not immediately clear to me, but the result of requireUserSession is passed into the fetch hook)
This fixes that and should avoid users to do an unnecessary check when hooking into fetch

Previously:

export default defineNitroPlugin(() => {
  sessionHooks.hook('fetch', (session, event) => {
    // session.user is possibly undefined, so we add a guard
    if (!session.user)
      // Do something

    // Do what you actually wanted to do with 'session.user'
  });
});

With this PR:

export default defineNitroPlugin(() => {
  sessionHooks.hook('fetch', (session, event) => {
    // session.user is defined so you can immediately do things without the need for a check
  });
});

Also, ActiveUserSession is not exposed because the type is completely defined by UserSession and User.

@atinux atinux merged commit 77c82e7 into atinux:main Apr 3, 2024
3 checks passed
@atinux
Copy link
Owner

atinux commented Apr 3, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants