You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -162,7 +162,7 @@ You can use the Amplify Auth category APIs to sign up and sign in your end users
162
162
163
163
You can use the `fetchAuthSession` API to check the auth sessions that are attached to the incoming requests in the middleware of your Next.js app to protect your routes. For example:
@@ -215,6 +215,166 @@ In this example, if the incoming request is not associated with a valid user ses
215
215
216
216
</Callout>
217
217
218
+
### (Preview) Perform authentication on the server side and enable HTTP-only cookies
219
+
220
+
<Calloutwarning>
221
+
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.
223
+
224
+
</Callout>
225
+
226
+
**Prerequisites**
227
+
228
+
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.
229
+
230
+
231
+
**Step 1: Specify the origin of your app in environment variables**
232
+
233
+
Add the following environment variables to your Next.js app. For example in a `.env` file:
234
+
235
+
```shell title=".env"
236
+
AMPLIFY_APP_ORIGIN=https://myapp.com
237
+
```
238
+
239
+
Ensure this environment variables is accessible in your Next.js app's server runtime.
240
+
241
+
**Step 2 - Export the `createAuthRouteHandlers` function**
242
+
243
+
`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.
|`/api/auth/sign-up`| Upon navigating an end user to this route, they’ll be redirected to the Amazon Cognito Managed Login sign-up form. After sign-up and sign-in, they’ll be redirected back to the route specified by the `redirectOnSignInComplete` parameter. |
300
+
|`/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 specified by the `redirectOnSignInComplete` parameter. |
301
+
|`/api/auth/sign-in?provider=<social-provider-name>`| Upon navigating an end user to this route, they’ll be redirected to Amazon Cognito Managed Login. Then, they’ll be redirected to the specified social provider sign-in page. After sign-in, they’ll be redirected back to the route specified by the `redirectOnSignOutComplete` parameter. |
302
+
|`/api/auth/sign-out`| Upon navigating an end user to this route, the end user will be signed out and redirected to the route specified by the redirectOnSignOutComplete parameter. |
303
+
|`/api/auth/sign-in-callback`| Amazon Cognito Managed Login redirects users back to this route after signing in. Amplify exchanges auth tokens and stores them as HTTP-only cookies in the browser cookie store. |
304
+
|`/api/auth/sign-out-callback`| Amazon Cognito Managed Login redirects an end user back to this router after signing out, Amplify revokes access token and refresh token and removes token cookies from browser cookie store. |
305
+
306
+
307
+
**Step 4 - Provide the redirect URLs to the Auth Resource in Amplify**
308
+
309
+
You can provide the callback API routes as the redirect URLs in the Auth resource configuration. For example:
0 commit comments