Skip to content

Commit

Permalink
docs format
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Nov 14, 2024
1 parent b211d06 commit 74d13c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
17 changes: 7 additions & 10 deletions website/src/pages/docs/features/envelop-plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,20 @@ tokens etc.
import { Plugin } from 'graphql-yoga'

function useAuth(): Plugin {
return {
onRequest({ request, fetchAPI, endResponse }) {
if (!request.headers.get('authorization')) {
endResponse(
new fetchAPI.Response(
null,
{
return {
onRequest({ request, fetchAPI, endResponse }) {
if (!request.headers.get('authorization')) {
endResponse(
new fetchAPI.Response(null, {
status: 401,
headers: {
'Content-Type': 'application/json'
}
}
})
)
)
}
}
}
}
}
```

Expand Down
15 changes: 9 additions & 6 deletions website/src/pages/docs/features/jwt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ For the setup mentioned above, you can use the following configuration for your
```ts filename="server.ts"
import { createYoga } from 'graphql-yoga'
import jwt from 'jsonwebtoken'
import { useJWT, createInlineSigningKeyProvider, createRemoteJwksSigningKeyProvider, extractFromHeader } from '@graphql-yoga/plugin-jwt'
import {
createInlineSigningKeyProvider,
createRemoteJwksSigningKeyProvider,
extractFromHeader,
useJWT
} from '@graphql-yoga/plugin-jwt'
import { getUserById, getUserByLogin } from './db'

const signingKey = process.env.JWT_SECRET
Expand All @@ -66,16 +71,14 @@ const yoga = createYoga({
],
// Configure where to look for the JWT token: in the headers, or cookies.
// By default, the plugin will look for the token in the 'authorization' header only.
tokenLookupLocations: [
extractFromHeader({ name: 'authorization', prefix: 'Bearer' }),
],
tokenLookupLocations: [extractFromHeader({ name: 'authorization', prefix: 'Bearer' })],
// Configure your token issuers/audience/algorithms verification options.
// By default, the plugin will only verify the HS256/RS256 algorithms.
// Please note that this should match the JWT signer issuer/audience/algorithms.
tokenVerification: {
issuer: 'http://my-issuer.com',
audience: 'my-audience',
algorithms: ['HS256', 'RS256'],
algorithms: ['HS256', 'RS256']
},
// Configure context injection after the token is verified.
// By default, the plugin will inject the token's payload into the context into the `jwt` field.
Expand All @@ -85,7 +88,7 @@ const yoga = createYoga({
// By default, the plugin will reject the request if the token is missing or invalid.
reject: {
missingToken: true,
invalidToken: true,
invalidToken: true
}
})
]
Expand Down

0 comments on commit 74d13c9

Please sign in to comment.