-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add Next.js server-side auth and HTTP-only cookie content #8224
base: main
Are you sure you want to change the base?
Conversation
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
|
||
**Step 2 - Export the `createAuthRouteHandlers` function** | ||
|
||
`createAuthRouteHandlers` function is created by the `createServerRunner` function call when you configure Amplify for server-side usage. You can export this function from your `amplifyServerUtils.ts` file. You can also configure cookie attributes with the `runtimeOptions` parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`createAuthRouteHandlers` function is created by the `createServerRunner` function call when you configure Amplify for server-side usage. You can export this function from your `amplifyServerUtils.ts` file. You can also configure cookie attributes with the `runtimeOptions` parameter. | |
The `createAuthRouteHandlers` function is created by the `createServerRunner` function call when you configure Amplify for server-side usage. You can export this function from your `amplifyServerUtils.ts` file. You can also configure cookie attributes with the `runtimeOptions` parameter. |
Sanity check: is the parameter here (and elsewhere below) still runtimeOptions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the parameter name is still runtimeOptions
.
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx
Outdated
Show resolved
Hide resolved
@@ -123,7 +123,7 @@ export default function ConfigureAmplifyClientSide() { | |||
|
|||
`layout.tsx`: | |||
|
|||
```jsx | |||
```jsx title="src/app/layout.tsx" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```jsx title="src/app/layout.tsx" | |
```tsx title="src/app/layout.tsx" |
@@ -108,7 +108,7 @@ If you're using the Next.js App Router, you can create a client component to con | |||
|
|||
`ConfigureAmplifyClientSide.ts`: | |||
|
|||
```typescript | |||
```typescript title="src/components/ConfigureAmplifyClientSide.tsx" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```typescript title="src/components/ConfigureAmplifyClientSide.tsx" | |
```tsx title="src/components/ConfigureAmplifyClientSide.tsx" |
@@ -215,6 +215,172 @@ In this example, if the incoming request is not associated with a valid user ses | |||
|
|||
</Callout> | |||
|
|||
### (Preview) Perform authentication on the server side and enable HTTP-only cookies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### (Preview) Perform authentication on the server side and enable HTTP-only cookies | |
### (Preview) Perform authentication on the server side and enable HttpOnly cookies |
nit for the attribute name
To authenticate users on the server side, you must enable either Amazon Cognito Managed Login or Hosted UI in your Amazon Cognito User Pool client. | ||
|
||
|
||
**Step 1 - Specify the origin of your app in environment variables** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we convert the steps to h4's?
loginWith: { | ||
email: true, | ||
externalProviders: { | ||
google: {...}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
google: {...}, | |
google: {/* ... */}, |
import config from '@/amplify_outputs.json'; | ||
|
||
export const { | ||
runWithAmplifyServerContext | ||
// highlight-start | ||
createAuthRouteHandlers, | ||
// highlight-end | ||
} = createServerRunner({ | ||
config, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import config from '@/amplify_outputs.json'; | |
export const { | |
runWithAmplifyServerContext | |
// highlight-start | |
createAuthRouteHandlers, | |
// highlight-end | |
} = createServerRunner({ | |
config, | |
import outputs from '@/amplify_outputs.json'; | |
export const { | |
runWithAmplifyServerContext | |
// highlight-start | |
createAuthRouteHandlers, | |
// highlight-end | |
} = createServerRunner({ | |
config: outputs, |
|
||
Add the following environment variables to your Next.js app. For example in a `.env` file: | ||
|
||
```shell title=".env" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```shell title=".env" | |
```shell title=".env" showLineNumbers={false} |
does this need to be added to the Hosting env as well?
|
||
```typescript | ||
```typescript title="src/components/client/ConfigureAmplifyClientSide.tsx" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```typescript title="src/components/client/ConfigureAmplifyClientSide.tsx" | |
```tsx title="src/components/client/ConfigureAmplifyClientSide.tsx" |
Description of changes:
Related GitHub issue #, if available:
Instructions
If this PR should not be merged upon approval for any reason, please submit as a DRAFT
Which product(s) are affected by this PR (if applicable)?
Which platform(s) are affected by this PR (if applicable)?
Please add the product(s)/platform(s) affected to the PR title
Checks
Does this PR conform to the styleguide?
Does this PR include filetypes other than markdown or images? Please add or update unit tests accordingly.
Are any files being deleted with this PR? If so, have the needed redirects been created?
Are all links in MDX files using the MDX link syntax rather than HTML link syntax?
ref: MDX:
[link](https://docs.amplify.aws/)
HTML:
<a href="https://docs.amplify.aws/">link</a>
When this PR is ready to merge, please check the box below
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.