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.
The return value of
requireUserSession
is guaranteed to have theuser
component defined. Previously, the return type was changed to reflect that fact but the session type passed to thefetch
hook was not. (It was not immediately clear to me, but the result ofrequireUserSession
is passed into thefetch
hook) This fixes that and should avoid users to do an unnecessary check when hooking intofetch
Previously:
With this PR:
Also,
ActiveUserSession
is not exposed because the type is completely defined byUserSession
andUser
.