Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: Gen2 doc doesn't have an equivalent page for adding this information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any relevant place. Only relatable location is the signOut page but that's for the common use-case and Gen2 has nothing on signInWithRedirect I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it here for Gen2.

Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,74 @@ function App() {
</Block>
</BlockSwitcher>

### Redirect URLs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section is redundant. By examining lines 744 and 746, I interpret that the change we are currently implementing is the inclusion of multiple redirects, which was actually a feature offered by v6 upon its release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On RN page, we don't have any info on redirects so I thought this will set up some context before diving into multiple redirects.


You can provide multiple _Sign in Redirect URI(s)_ & _Sign out redirect URI(s)_.

If you have multiple redirect URI inputs, you'll need to pass them in your Amplify configuration. For example:

```javascript
Amplify.configure({
Auth: {
Cognito: {
loginWith: {
oauth: {
redirectSignIn: [
'myDevApp://'
],
redirectSignOut: [
'myDevApp://',
'myProdApp://'
],
...oauthConfig
}
},
...userPoolConfig
}
}
});
```

#### Option to specify a redirect URL upon signOut
If you have multiple redirect urls configured, you may choose to override the default behavior of selecting a redirect url and provide the one of your choosing when calling `signOut`. The provided redirect url should match at least one of the configured redirect urls. If no redirect url is provided to `signOut`, the first item from the the configured redirect urls list that does not contain a http nor https prefix will be picked.

```ts
import { Amplify } from 'aws-amplify';
import { signOut } from 'aws-amplify/auth';

Amplify.configure({
Auth: {
Cognito: {
loginWith: {
oauth: {
redirectSignIn: [
'myDevApp://'
],
redirectSignOut: [
'myDevApp://',
'myProdApp://'
],
...oauthConfig
}
},
...userPoolConfig
}
}
});

function handleSignOut() {
signOut({
global: false,
oauth: {
redirectUrl: 'myDevApp://'
}
});
}


```
<Callout> Irrespective of whether a `redirectUrl` is provided to the `signOut`, an item that does not contain a http or https string is expected to be present in the configured redirect urls list. This is because iOS requires we provide an appScheme when creating the web session. </Callout>

</InlineFilter>

<InlineFilter filters={["javascript", "angular", "nextjs", "react", "vue"]}>
Expand Down Expand Up @@ -943,6 +1011,43 @@ function App() {

</Accordion>

#### Option to specify a redirect URL upon signOut
If you have multiple redirect urls configured, you may choose to override the default behavior of selecting a redirect url and provide the one of your choosing when calling `signOut`. The provided redirect url should match at least one of the configured redirect urls. If no redirect url is provided to `signOut`, one will be selected based on the current app domain.

```ts
import { Amplify } from 'aws-amplify';
import { signOut } from 'aws-amplify/auth';

Amplify.configure({
Auth: {
Cognito: {
loginWith: {
oauth: {
redirectSignIn: [
'http://localhost:3000/',
'https://www.example.com/'
],
redirectSignOut: [
'http://localhost:3000/',
'https://www.example.com/'
],
...oauthConfig
}
},
...userPoolConfig
}
}
});

signOut({
global: false,
oauth: {
redirectUrl: 'https://www.example.com/'
}
});

```

### (Required for Multi-Page Applications) Complete Social Sign In after Redirect

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:
Expand Down