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
feat: Implement logout functionality for Gen 2 RSC Quickstart (#6839)
* update RSC quickstart with logout functionality
* make option plural per feedback
* add a section to have callback urls redirect to `/login` for Social Providers.
Copy file name to clipboardExpand all lines: src/pages/gen2/start/quickstart/nextjs-app-router-server-components/index.mdx
+89-22Lines changed: 89 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,51 @@ export default function RootLayout({
94
94
}
95
95
```
96
96
97
-
### Add a login page
97
+
### Configure Amplify Server Side
98
+
99
+
First, install the Amplify Next.js Adapter:
100
+
101
+
```bash
102
+
npm install @aws-amplify/adapter-nextjs
103
+
```
104
+
105
+
Next, create a `utils/amplify-utils.ts` file from the root of the project and paste the code below. `runWithAmplifyServerContext`, `cookiesClient` and `AuthGetCurrentUserServer` are declared here and will be used to gain access to Amplify assets from the server.
First, create a client side Login component in the `components` folder that will be wrapped in `withAuthenticator`. If the user is logged in, they will be redirected to the index route, otherwise the [Amplify UI Authenticator component](https://ui.docs.amplify.aws/react/connected-components/authenticator) will be rendered.
100
144
@@ -133,7 +177,7 @@ export default function LoginPage() {
133
177
134
178
<Accordiontitle="Custom <Authenticator> example">
135
179
136
-
Some applications require more customization for the `<Authenticator>` component. The following example shows how to add a custom Header to the `<Authenticator>`. For this use, you will not need the `Login` file in the `components` folder but can do everything through the `page` file in the `app/login/` folder. For more customization option, see [Authenticator Customization](https://ui.docs.amplify.aws/react/connected-components/authenticator/customization).
180
+
Some applications require more customization for the `<Authenticator>` component. The following example shows how to add a custom Header to the `<Authenticator>`. For this use, you will not need the `Login` file in the `components` folder but can do everything through the `page` file in the `app/login/` folder. For more customization options, see [Authenticator Customization](https://ui.docs.amplify.aws/react/connected-components/authenticator/customization).
137
181
138
182
```ts title="app/login/page.tsx"
139
183
// app/login/page.tsx - Custom <Authenticator>
@@ -184,37 +228,56 @@ export default function Login() {
184
228
</Accordion>
185
229
186
230
187
-
### Configure Amplify Server Side
231
+
Finally, create a `Logout` component to be used later.
188
232
189
-
First, install the Amplify Next.js Adapter:
233
+
```ts title="components/Logout.tsx"
234
+
// components/Logout.tsx
190
235
191
-
```bash
192
-
npm install @aws-amplify/adapter-nextjs
193
-
```
236
+
"use client";
194
237
195
-
Next, create a `utils/amplify-utils.ts` file from the root of the project and paste the code below. `runWithAmplifyServerContext` and `cookiesClient` are declared here and will be used to gain access to Amplify assets from the server.
**Note**: If using [Amplify UI Social Providers](https://ui.docs.amplify.aws/react/connected-components/authenticator/configuration#social-providers), set the `callbackUrls` for the `/login` route when [configuring social sign-in for your Gen 2 backend](https://docs.amplify.aws/gen2/build-a-backend/auth/add-social-provider/#configure-social-sign-in-backend), as shown below.
0 commit comments