Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change Not Authorised to Not Authorized #1527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/graphql-shield/src/shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function normalizeOptions(options: IOptionsConstructor): IOptions {
debug: options.debug !== undefined ? options.debug : false,
allowExternalErrors: withDefault(false)(options.allowExternalErrors),
fallbackRule: withDefault<ShieldRule>(allow)(options.fallbackRule),
fallbackError: withDefault<IFallbackErrorType>(new Error('Not Authorised!'))(options.fallbackError),
fallbackError: withDefault<IFallbackErrorType>(new Error('Not Authorized!'))(options.fallbackError),
hashFunction: withDefault<IHashFunction>(hash)(options.hashFunction),
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-shield/tests/fallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ describe('external errors can be controled correctly', () => {
/* Tests */

expect(res.data).toBeNull()
expect(res.errors?.[0]?.message).toBe('Not Authorised!')
expect(res.errors?.[0]?.message).toBe('Not Authorized!')
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-shield/tests/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ describe('logic rules', () => {
customRuleErrorString: 'customRuleErrorString',
})
expect(res.errors?.map((err) => err.message)).toEqual([
'Not Authorised!',
'Not Authorised!',
'Not Authorized!',
'Not Authorized!',
])
})

Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/advanced/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> This is a list of frequently asked questions and their short explanations.

## When a single field is "Not Authorised!" the entire parent object returns null.
## When a single field is "Not Authorized!" the entire parent object returns null.

This occurs when a non-nullable field (specified in the schema) returns a null value (due to GraphQL Shield blocking the field's value). GraphQL is a strongly typed language - the schema serves as a contract between client and server - which requires that the server response follow the schema definition.

Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/docs/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ If you wish to see errors thrown inside resolvers, you can set `allowExternalErr

## Global Fallback Error

GraphQL Shield allows you to set a globally defined fallback error that is used instead of `Not Authorised!` default response. This might be particularly useful for localization. You can use `string` or even custom `Error` to define it.
GraphQL Shield allows you to set a globally defined fallback error that is used instead of `Not Authorized!` default response. This might be particularly useful for localization. You can use `string` or even custom `Error` to define it.

```ts
const permissions = shield(
Expand Down
4 changes: 2 additions & 2 deletions website/src/pages/docs/shield.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const permissions = shield({
| allowExternalErrors | false | false | Toggle catching internal errors. |
| debug | false | false | Toggle debug mode. |
| fallbackRule | false | allow | The default rule for every "rule-undefined" field. |
| fallbackError | false | Error('Not Authorised!') | Error Permission system fallbacks to. |
| fallbackError | false | Error('Not Authorized!') | Error Permission system fallbacks to. |
| hashFunction | false | [object-hash](https://github.com/puleos/object-hash) | Hashing function to use for `strict` cache |

By default `shield` ensures no internal data is exposed to client if it was not meant to be. Therefore, all thrown errors during execution resolve in `Not Authorised!` error message if not otherwise specified using `error` wrapper. This can be turned off by setting `allowExternalErrors` option to `true`.
By default `shield` ensures no internal data is exposed to client if it was not meant to be. Therefore, all thrown errors during execution resolve in `Not Authorized!` error message if not otherwise specified using `error` wrapper. This can be turned off by setting `allowExternalErrors` option to `true`.