Skip to content

Commit c46cef0

Browse files
authored
chore(js-auth): complete oauth in MPAs (aws-amplify#6741)
1 parent 8b07619 commit c46cef0

File tree

1 file changed

+20
-0
lines changed
  • src/pages/[platform]/build-a-backend/auth/add-social-provider

1 file changed

+20
-0
lines changed

src/pages/[platform]/build-a-backend/auth/add-social-provider/index.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,26 @@ function App() {
944944
945945
</Accordion>
946946
947+
### (Required for Multi-Page Applications) Complete Social Sign In after Redirect
948+
949+
If you are developing a multi-page application, and the redirected page is not the same page that initiated the sign in, you will need to add the following code to the redirected page to ensure the sign in gets completed:
950+
951+
```ts
952+
import 'aws-amplify/auth/enable-oauth-listener';
953+
```
954+
955+
<Callout>
956+
957+
**NOTE:** The listener only works on the client side in the context of a SSR-enabled project, so ensure to import the listener on the client side only. For example, in a Next.js project, you should add the above import statement to a component that renders on the client side only by `'use client'`.
958+
959+
</Callout>
960+
961+
<Accordion eyebrow="Under the hood" headingLevel="4" title="Why Social Sign In needs to be explicitly handled for Multi-Page Applications">
962+
963+
When you import and use the `signInWithRedirect` function, it will add a listener as a side effect that will complete the social sign in when an end user is redirected back to your app. This works well in a single-page application but in a multi-page application, you might get redirected to a page that doesn't include the listener that was originally added as a side-effect. Hence you must include the specific OAuth listener on your login success page.
964+
965+
</Accordion>
966+
947967
</InlineFilter>
948968
949969
### Custom Providers

0 commit comments

Comments
 (0)