-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
7 changed files
with
50 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MiddlewareFn } from 'type-graphql'; | ||
import { ForbiddenError } from 'apollo-server'; | ||
|
||
import { ResolverContext } from '@typeDefs/resolver'; | ||
import { hasAdminRole } from '@validation/admin'; | ||
|
||
export const isAdmin: MiddlewareFn<ResolverContext> = async ( | ||
{ context }, | ||
next | ||
) => { | ||
if (!context.me) { | ||
throw new ForbiddenError('Not authenticated as user.'); | ||
} | ||
|
||
if (!hasAdminRole(context.me)) { | ||
throw new ForbiddenError('No admin user.'); | ||
} | ||
|
||
return next(); | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as ROLES from '@constants/roles'; | ||
import { User } from '@typeDefs/user'; | ||
|
||
export const hasAdminRole = (user: User) => | ||
export const hasAdminRole = (user: User | null | undefined) => | ||
user && user.customClaims && user.customClaims[ROLES.ADMIN]; |