-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
213 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import compact from 'just-compact' | ||
import { type LiteralUnion } from 'type-fest' | ||
|
||
import { type Namespaces } from '@weareinreach/db/generated/namespaces' | ||
|
||
type Namespace = LiteralUnion<Namespaces, string> | ||
export const nsFormatter = | ||
(baseNamespaces: Namespace | Namespace[]) => (additionalNamespaces?: string | string[]) => | ||
compact<Namespace>([ | ||
...(Array.isArray(baseNamespaces) ? baseNamespaces : [baseNamespaces]), | ||
...(Array.isArray(additionalNamespaces) ? additionalNamespaces : [additionalNamespaces]), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { checkPermissions } from './next-auth/session.browser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type Session } from 'next-auth' | ||
|
||
import { type Permission } from '@weareinreach/db/generated/permission' | ||
|
||
export interface CheckPermissionsParams { | ||
session: Session | null | ||
permissions: Permission | Permission[] | ||
has: 'all' | 'some' | ||
} | ||
export const checkPermissions = ({ session, permissions, has = 'all' }: CheckPermissionsParams) => { | ||
if (!session) return false | ||
if (session.user.permissions.includes('root')) return true | ||
const userPerms = new Set(session.user.permissions) | ||
const permsToCheck = Array.isArray(permissions) ? permissions : [permissions] | ||
return has === 'all' | ||
? permsToCheck.every((perm) => userPerms.has(perm)) | ||
: permsToCheck.some((perm) => userPerms.has(perm)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.