-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: circumvent permission checks when developing locally via serve-…
…dev (credits go to bradleyDean)
- Loading branch information
Showing
5 changed files
with
60 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* This file is used when starting the server via `yarn serve-dev` | ||
* It bypasses the authentication for local development and allows all queries and mutations. | ||
*/ | ||
import muuid, { MUUID } from 'uuid-mongodb' | ||
import { AuthUserType } from '../../types.js' | ||
import { logger } from '../../logger.js' | ||
|
||
export const localDevBypassAuthMiddleware = (() => { | ||
const testUUID: MUUID = muuid.v4() | ||
|
||
return async ({ req }): Promise<any> => { | ||
const user: AuthUserType = { | ||
roles: ['user_admin', 'org_admin', 'editor'], | ||
uuid: testUUID, | ||
isBuilder: false | ||
} | ||
logger.info(`The user.roles for this session is: ${user.roles.toString()}`) | ||
return { user } | ||
} | ||
})() |
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,19 @@ | ||
/* | ||
* This file is used when starting the server via `yarn serve-dev` | ||
* It bypasses the authentication for local development and allows all queries and mutations. | ||
*/ | ||
import { shield, allow } from 'graphql-shield' | ||
|
||
const localDevBypassAuthPermissions = shield({ | ||
Query: { | ||
'*': allow | ||
}, | ||
Mutation: { | ||
'*': allow | ||
} | ||
}, { | ||
allowExternalErrors: true, | ||
fallbackRule: allow | ||
}) | ||
|
||
export default localDevBypassAuthPermissions |
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