Skip to content

Commit c2d6717

Browse files
authored
fix(next-app-router) starter tutorial authenticator build issue (#8392)
1 parent bf8d05a commit c2d6717

File tree

1 file changed

+21
-5
lines changed
  • src/pages/[platform]/start/quickstart/nextjs-app-router-client-components

1 file changed

+21
-5
lines changed

src/pages/[platform]/start/quickstart/nextjs-app-router-client-components/index.mdx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,33 @@ This should start a local dev server at http://localhost:3000.
219219

220220
The starter application already has a pre-configured auth backend defined in the **amplify/auth/resource.ts** file. We've configured it to support email and password login but you can extend it to support a variety of login mechanisms, including Google, Amazon, Sign In With Apple, and Facebook.
221221

222-
The fastest way to get your login experience up and running is to use our Authenticator UI component. In your **app/layout.tsx** file, import the Authenticator UI component and wrap the children or pages components.
222+
The fastest way to get your login experience up and running is to use our Authenticator UI component. To properly integrate it with Next.js App Router, we'll create a client component wrapper and use it in the layout.
223223

224+
First, create an AuthenticatorWrapper.tsx file in your app directory:
224225

225-
```tsx title="app/layout.tsx"
226+
```tsx title="app/AuthenticatorWrapper.tsx"
226227
"use client"
227228

229+
import { Authenticator } from "@aws-amplify/ui-react";
230+
231+
export default function AuthenticatorWrapper({
232+
children,
233+
}: {
234+
children: React.ReactNode;
235+
}) {
236+
return <Authenticator>{children}</Authenticator>;
237+
}
238+
```
239+
240+
Next, update your app/layout.tsx file to import and use the AuthenticatorWrapper component:
241+
242+
```tsx title="app/layout.tsx"
243+
228244
import React from "react";
229245
import { Amplify } from "aws-amplify";
230246
import "./app.css";
231247
// highlight-start
232-
import { Authenticator } from "@aws-amplify/ui-react";
248+
import AuthenticatorWrapper from "./AuthenticatorWrapper";
233249
import "@aws-amplify/ui-react/styles.css";
234250
// highlight-end
235251
import outputs from "@/amplify_outputs.json";
@@ -245,9 +261,9 @@ export default function RootLayout({
245261
// highlight-start
246262
<html lang="en">
247263
<body>
248-
<Authenticator>
264+
<AuthenticatorWrapper>
249265
{children}
250-
</Authenticator>
266+
</AuthenticatorWrapper>
251267
</body>
252268
</html>
253269
// highlight-end

0 commit comments

Comments
 (0)