diff --git a/docs/docs/serverless-functions.md b/docs/docs/serverless-functions.md index 940ec6cc6370..fc327a39063e 100644 --- a/docs/docs/serverless-functions.md +++ b/docs/docs/serverless-functions.md @@ -742,13 +742,16 @@ The `useRequireAuth` wrapper configures your handler's `context` so that you can - import `useRequireAuth` from `@redwoodjs/graphql-server` - import your app's custom `getCurrentUser` and the `isAuthenticated` check from `src/lib/auth` +- import your auth provider's `authDecoder` - implement your serverless function as you would, but do not `export` it (see `myHandler` below). -- pass your implementation and `getCurrentUser` to the `useRequireAuth` wrapper and export its return +- pass your implementation, `getCurrentUser` and `authDecoder` to the `useRequireAuth` wrapper and export its return - check if the user `isAuthenticated()` and, if not, handle the unauthenticated case by returning a `401` status code (for example) ```tsx import type { APIGatewayEvent, Context } from 'aws-lambda' +// highlight-next-line +import { authDecoder } from '@redwoodjs/auth-dbauth-api' // highlight-next-line import { useRequireAuth } from '@redwoodjs/graphql-server' @@ -772,20 +775,21 @@ const myHandler = async (event: APIGatewayEvent, context: Context) => { data: 'myHandler function', }), } + // highlight-start } else { - // highlight-start logger.error('Access to myHandler was denied') return { statusCode: 401, } - // highlight-end } + // highlight-end } export const handler = useRequireAuth({ handlerFn: myHandler, getCurrentUser, + authDecoder, }) ``` @@ -805,17 +809,10 @@ As there is no login flow when using functions, the `useRequireAuth` check assum In your request, you must include the following headers: -- the auth provider type that your application is using +- the auth provider type that your application is using, e.g. `dbAuth` - the Bearer token (JWT access token) - if using dbAuth, then also the dbAuth Cookie -You can find the auth provider type as the `type` attribute set on the `AuthProvider`: - -```jsx - - -``` - For example: ```bash diff --git a/docs/docs/tutorial/chapter6/the-redwood-way.md b/docs/docs/tutorial/chapter6/the-redwood-way.md index 0b6a2c2ab7aa..4bb4388893c2 100644 --- a/docs/docs/tutorial/chapter6/the-redwood-way.md +++ b/docs/docs/tutorial/chapter6/the-redwood-way.md @@ -114,7 +114,7 @@ export default { -```tsx title="web/src/components/Comment/Comment.stories.txs" +```tsx title="web/src/components/Comment/Comment.stories.tsx" import Comment from './Comment' export const generated = () => {