Open YujiAdachi opened 10 months ago
Hello, @YujiAdachi 👋 and thank you for opening this issue. I've marked this as a feature request and will review it with our team internally for support to allow redirects to be undefined
.
@YujiAdachi, can you expand on what the use case would be for this? Are you just wanting it to redirect back to the Hosted UI page? If we could understand the goal of this a little better, that would be appreciated!
Hello @cwomack,
Thank you for considering my feature request. The primary use case for allowing undefined
in redirectSignOut is to enable more flexible sign-out flows in applications where a redirect is not necessary or desired post-logout. This would be particularly useful in scenarios where the app needs to remain on the same page or perform other actions after logout, without an automatic redirection to a different URL.
The proposed patch for handleOAuthSignOut.native.ts aims to accommodate this flexibility without impacting existing functionality. It ensures that if redirectSignOut is undefined
, the app won't attempt a redirect, aligning with the behavior seen in previous versions of Amplify JS.
I'm attaching a code snippet.
import {Hub} from '@aws-amplify/core';
import {Amplify} from 'aws-amplify';
import {
AuthUser,
getCurrentUser,
signInWithRedirect,
signOut,
} from 'aws-amplify/auth';
import React, {useEffect, useState} from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';
const awsmobile = {
...
oauth: {
domain: 'domain.auth.ap-northeast-1.amazoncognito.com',
scope: [
'phone',
'email',
'openid',
'profile',
'aws.cognito.signin.user.admin',
],
redirectSignIn: 'mobile://',
redirectSignOut: undefined,
responseType: 'code',
},
};
Amplify.configure(awsmobile);
const App = () => {
const [user, setUser] = useState<AuthUser | null>(null);
useEffect(() => {
const unsubscribe = Hub.listen('auth', ({payload}) => {
switch (payload.event) {
case 'signedIn':
case 'signedOut':
case 'signInWithRedirect':
getUser();
break;
default:
break;
}
});
getUser();
return unsubscribe;
}, []);
const getUser = async (): Promise<void> => {
try {
const currentUser = await getCurrentUser();
setUser(currentUser);
} catch (error) {
setUser(null);
}
};
return (
<View style={styles.container}>
<Text>AwesomeProject</Text>
<Text>{user?.username}</Text>
<Button
title="Sign In"
onPress={() => signInWithRedirect({provider: 'Apple'})}
/>
<Button title="Sign Out" onPress={() => signOut()} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
Hello @cwomack,
How is the progress on this issue going? Please let me know if there is anything I can help with.
Is this related to a new or existing framework?
React Native
Is this related to a new or existing API?
No response
Is this related to another service?
No response
Describe the feature you'd like to request
I would like to request a feature in Amplify-JS v6 that allows undefined to be set for the redirectSignOut in OAuthSignOut. It is important to be able to set this property to undefined when there is no need to redirect after a user logs out. Since the current version does not permit this, I am requesting the implementation of this functionality. Additionally, I would like to point out that in Amplify JS v5, setting undefined for redirectSignOut did not cause any errors.
Describe the solution you'd like
As a solution, I propose a patch file for the handleOAuthSignOut.native.ts file, which is part of the Amplify-JS OAuthSignOut functionality. This patch modifies the conditional statement to work correctly even when the redirectSignOut property is an empty array or undefined.
Describe alternatives you've considered
I have not thought of any alternatives. If there are any good workarounds, please let me know.
Additional context
Is this something that you'd be interested in working on?