Skip to content

Commit 3b53898

Browse files
committed
chore: resolve comments
1 parent 0e0a7de commit 3b53898

File tree

2 files changed

+26
-25
lines changed
  • src/pages
    • [platform]/build-a-backend/server-side-rendering
    • gen1/[platform]/build-a-backend/server-side-rendering/nextjs

2 files changed

+26
-25
lines changed

src/pages/[platform]/build-a-backend/server-side-rendering/index.mdx

+15-14
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ If you're using the Next.js App Router, you can create a client component to con
108108

109109
`ConfigureAmplifyClientSide.ts`:
110110

111-
```typescript title="src/components/ConfigureAmplifyClientSide.tsx"
111+
```tsx title="src/components/ConfigureAmplifyClientSide.tsx"
112112
'use client';
113113

114114
import { Amplify } from 'aws-amplify';
@@ -123,7 +123,7 @@ export default function ConfigureAmplifyClientSide() {
123123

124124
`layout.tsx`:
125125

126-
```jsx title="src/app/layout.tsx"
126+
```tsx title="src/app/layout.tsx"
127127
import ConfigureAmplifyClientSide from '@/components/ConfigureAmplifyClientSide';
128128
import './globals.css';
129129

@@ -215,11 +215,11 @@ In this example, if the incoming request is not associated with a valid user ses
215215

216216
</Callout>
217217

218-
### (Preview) Perform authentication on the server side and enable HTTP-only cookies
218+
### (Experimental) Perform authentication on the server side and enable HttpOnly cookies
219219

220220
<Callout warning>
221221

222-
**NOTE:** Once you enable the server-side sign-in feature, auth tokens are stored in HTTP-only cookies and you may not change the HTTP-only attribute. Since these cookies are inaccessible from client-side scripts, you won’t be able to use any Amplify JS APIs on the client side. Therefore, you don’t need to configure Amplify on the client side.
222+
**NOTE:** Once you enable the server-side sign-in feature, auth tokens are stored in HttpOnly cookies and you may not change the HttpOnly attribute. Since these cookies are inaccessible from client-side scripts, you won’t be able to use any Amplify JS APIs on the client side. Therefore, you don’t need to configure Amplify on the client side. You can keep using [these Amplify JS server-side APIs](/[platform]/build-a-backend/server-side-rendering/#supported-apis-for-nextjs-server-side-usage) on the server side.
223223

224224
</Callout>
225225

@@ -228,33 +228,33 @@ In this example, if the incoming request is not associated with a valid user ses
228228
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.
229229

230230

231-
**Step 1 - Specify the origin of your app in environment variables**
231+
#### Step 1 - Specify the origin of your app in environment variables
232232

233233
Add the following environment variables to your Next.js app. For example in a `.env` file:
234234

235-
```shell title=".env"
235+
```shell title=".env" showLineNumbers={false}
236236
AMPLIFY_APP_ORIGIN=https://myapp.com
237237
```
238238

239239
Ensure this environment variables is accessible in your Next.js app's server runtime.
240240

241241
> **Note:** Token cookies are transmitted via server-side authentication flows. In production environments, it is recommended to use HTTPS as the origin for enhanced security.
242242
243-
**Step 2 - Export the `createAuthRouteHandlers` function**
243+
#### Step 2 - Export the `createAuthRouteHandlers` function
244244

245245
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.
246246

247247
```typescript title="utils/amplifyServerUtils.ts"
248248
import { createServerRunner } from '@aws-amplify/adapter-nextjs';
249-
import config from '@/amplify_outputs.json';
249+
import outputs from '@/amplify_outputs.json';
250250

251251
export const {
252252
runWithAmplifyServerContext
253253
// highlight-start
254254
createAuthRouteHandlers,
255255
// highlight-end
256256
} = createServerRunner({
257-
config,
257+
config: outputs,
258258
// highlight-start
259259
runtimeOptions: {
260260
cookies: {
@@ -267,7 +267,7 @@ export const {
267267
});
268268
```
269269

270-
**Step 3 - Set up the Auth API routes**
270+
#### Step 3 - Set up the Auth API routes
271271

272272
Create an API route using the `createAuthRouteHandlers` function. For example:
273273

@@ -302,15 +302,15 @@ With the above example, Amplify generates the following API routes:
302302
| `/api/auth/sign-in` | Upon navigating an end user to this route, they’ll be redirected to the Amazon Cognito Managed Login sign-in form. After sign-in, they’ll be redirected back to the route `/api/auth/sign-in-callback`. |
303303
| `/api/auth/sign-in?provider=<social-provider-name>` | Upon navigating an end user to this route, they’ll be redirected to first to the Amazon Cognito Managed Login and then the specified social provider sign-in page. After sign-in, they’ll be redirected back to the route `/api/auth/sign-in-callback`. |
304304
| `/api/auth/sign-out` | Upon navigating an end user to this route, the end user will be signed out and redirected to the route `/api/auth/sign-out-callback`. |
305-
| `/api/auth/sign-in-callback` | Amazon Cognito Managed Login redirects an end user back to this route after signing in. Amplify exchanges auth tokens and stores them as HTTP-only cookies in the browser cookie store, then redirects the end user back to the route specified by the `redirectOnSignInComplete` parameter. |
305+
| `/api/auth/sign-in-callback` | Amazon Cognito Managed Login redirects an end user back to this route after signing in. Amplify exchanges auth tokens and stores them as HttpOnly cookies in the browser cookie store, then redirects the end user back to the route specified by the `redirectOnSignInComplete` parameter. |
306306
| `/api/auth/sign-out-callback` | Amazon Cognito Managed Login redirects an end user back to this route after signing out, Amplify revokes access token and refresh token and removes token cookies from browser cookie store, then redirects the end user back to the route specified by the `redirectOnSignOutComplete` parameter. |
307307

308308
> **Note:** A signing-out call involves multiple steps, including signing out from Amazon Cognito Managed Login, revoking tokens, and removing cookies. If the user closes the browser during the process, the following may occur:
309309
>
310310
> 1. auth token have not been revoked - user remains signed in
311311
> 2. auth token have been revoked but cookies have not been removed - cookies will be removed when the user visits the app again
312312
313-
**Step 4 - Provide the redirect URLs to the Auth Resource in Amplify**
313+
#### Step 4 - Provide the redirect URLs to the Auth Resource in Amplify
314314

315315
You can provide the callback API routes as the redirect URLs in the Auth resource configuration. For example:
316316

@@ -319,7 +319,7 @@ export const auth = defineAuth({
319319
loginWith: {
320320
email: true,
321321
externalProviders: {
322-
google: {...},
322+
google: {/* ... */},
323323
// highlight-start
324324
callbackUrls: ["https://myapp.com/api/auth/sign-in-callback"],
325325
logoutUrls: ["https://myapp.com/api/auth/sign-out-callback"],
@@ -328,7 +328,8 @@ export const auth = defineAuth({
328328
},
329329
});
330330
```
331-
**Step 5 - Use Anchor link for initiating server-side authentication flows**
331+
332+
#### Step 5 - Use Anchor link for initiating server-side authentication flows
332333

333334
Use HTML anchor links to navigate users to the sign-in and sign-up routes. For example:
334335

src/pages/gen1/[platform]/build-a-backend/server-side-rendering/nextjs/index.mdx

+11-11
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ If you're using the Next.js App Router, you can create a client component to con
110110

111111
`ConfigureAmplifyClientSide.tsx`:
112112

113-
```typescript title="src/components/client/ConfigureAmplifyClientSide.tsx"
113+
```tsx title="src/components/client/ConfigureAmplifyClientSide.tsx"
114114
'use client';
115115

116116
import { Amplify } from 'aws-amplify';
@@ -125,7 +125,7 @@ export default function ConfigureAmplifyClientSide() {
125125

126126
`layout.tsx`:
127127

128-
```jsx title="src/app/layout.tsx"
128+
```tsx title="src/app/layout.tsx"
129129
import ConfigureAmplifyClientSide from '@/components/ConfigureAmplifyClientSide';
130130
import './globals.css';
131131

@@ -217,11 +217,11 @@ In this example, if the incoming request is not associated with a valid user ses
217217

218218
</Callout>
219219

220-
### (Preview) Perform authentication on the server side and enable HTTP-only cookies
220+
### (Experimental) Perform authentication on the server side and enable HttpOnly cookies
221221

222222
<Callout warning>
223223

224-
**NOTE:** Once you enable the server-side sign-in feature, auth tokens are stored in HTTP-only cookies and you may not change the HTTP-only attribute. Since these cookies are inaccessible from client-side scripts, you won’t be able to use any Amplify JS APIs on the client side. Therefore, you don’t need to configure Amplify on the client side.
224+
**NOTE:** Once you enable the server-side sign-in feature, auth tokens are stored in HttpOnly cookies and you may not change the HttpOnly attribute. Since these cookies are inaccessible from client-side scripts, you won’t be able to use any Amplify JS APIs on the client side. Therefore, you don’t need to configure Amplify on the client side. You can keep using [these Amplify JS server-side APIs](/gen1/[platform]/build-a-backend/server-side-rendering/nextjs/#supported-apis-for-nextjs-server-side-usage) on the server side.
225225

226226
</Callout>
227227

@@ -230,19 +230,19 @@ In this example, if the incoming request is not associated with a valid user ses
230230
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.
231231

232232

233-
**Step 1 - Specify the origin of your app in environment variables**
233+
#### Step 1 - Specify the origin of your app in environment variables
234234

235235
Add the following environment variables to your Next.js app. For example in a `.env` file:
236236

237-
```shell title=".env"
237+
```shell title=".env" showLineNumbers={false}
238238
AMPLIFY_APP_ORIGIN=https://myapp.com
239239
```
240240

241241
Ensure this environment variables is accessible in your Next.js app's server runtime.
242242

243243
> **Note:** Token cookies are transmitted via server-side authentication flows. In production environments, it is recommended to use HTTPS as the origin for enhanced security.
244244
245-
**Step 2 - Export the `createAuthRouteHandlers` function**
245+
#### Step 2 - Export the `createAuthRouteHandlers` function
246246

247247
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.
248248

@@ -269,7 +269,7 @@ export const {
269269
});
270270
```
271271

272-
**Step 3 - Set up the Auth API routes**
272+
#### Step 3 - Set up the Auth API routes
273273

274274
Create an API route using the `createAuthRouteHandlers` function. For example:
275275

@@ -304,15 +304,15 @@ With the above example, Amplify generates the following API routes:
304304
| `/api/auth/sign-in` | Upon navigating an end user to this route, they’ll be redirected to the Amazon Cognito Managed Login sign-in form. After sign-in, they’ll be redirected back to the route `/api/auth/sign-in-callback`. |
305305
| `/api/auth/sign-in?provider=<social-provider-name>` | Upon navigating an end user to this route, they’ll be redirected to first to the Amazon Cognito Managed Login and then the specified social provider sign-in page. After sign-in, they’ll be redirected back to the route `/api/auth/sign-in-callback`. |
306306
| `/api/auth/sign-out` | Upon navigating an end user to this route, the end user will be signed out and redirected to the route `/api/auth/sign-out-callback`. |
307-
| `/api/auth/sign-in-callback` | Amazon Cognito Managed Login redirects an end user back to this route after signing in. Amplify exchanges auth tokens and stores them as HTTP-only cookies in the browser cookie store, then redirects the end user back to the route specified by the `redirectOnSignInComplete` parameter. |
307+
| `/api/auth/sign-in-callback` | Amazon Cognito Managed Login redirects an end user back to this route after signing in. Amplify exchanges auth tokens and stores them as HttpOnly cookies in the browser cookie store, then redirects the end user back to the route specified by the `redirectOnSignInComplete` parameter. |
308308
| `/api/auth/sign-out-callback` | Amazon Cognito Managed Login redirects an end user back to this route after signing out, Amplify revokes access token and refresh token and removes token cookies from browser cookie store, then redirects the end user back to the route specified by the `redirectOnSignOutComplete` parameter. |
309309

310310
> **Note:** A signing-out call involves multiple steps, including signing out from Amazon Cognito Managed Login, revoking tokens, and removing cookies. If the user closes the browser during the process, the following may occur:
311311
>
312312
> 1. auth token have not been revoked - user remains signed in
313313
> 2. auth token have been revoked but cookies have not been removed - cookies will be removed when the user visits the app again
314314
315-
**Step 4 - Provide the redirect URLs to the Auth Resource in Amplify**
315+
#### Step 4 - Provide the redirect URLs to the Auth Resource in Amplify
316316

317317
You can run `amplify add auth` or `amplify update auth` to provide the callback API routes as the redirect URLs. See [Configure the Auth category](/gen1/[platform]/build-a-backend/auth/add-social-provider/#configure-the-auth-category) for more details. With the above example, you can provide the following redirect URLs:
318318

@@ -324,7 +324,7 @@ https://myapp.com/api/auth/sign-in-callback
324324
https://myapp.com/api/auth/sign-out-callback
325325
```
326326

327-
**Step 5 - Use Anchor link for initiating server-side authentication flows**
327+
#### Step 5 - Use Anchor link for initiating server-side authentication flows
328328

329329
Use HTML anchor links to navigate users to the sign-in and sign-up routes. For example:
330330

0 commit comments

Comments
 (0)