vevcom / projectNext

Project Next is Omegas new website coming soon
MIT License
7 stars 0 forks source link

Refactor/auth get user and use user #216

Closed Paulijuz closed 5 months ago

Paulijuz commented 5 months ago

This PR splits off the memberships and permssions from the user object to their own properties of the session object. The user object no longer has permissions or memberships as properties. This means that getUser and useUser returns permissions and memberships on the same level as the user object. The new usage looks like this:

 const { user, permissions, memberships, authorized, status} = useUser({
        requiredPermissions,
        shouldRedirect: false,
})

Permissions and memberships are always returned as arrays, even if there is no user. If there is no user the permissions array will include the default permissions while the memebrships array will be empty. This is so that one can always safely do permissions.includes().