Social Auth not persisting in React Native
See original GitHub issueDescribe the bug I’ve implemented the withOAuth HOC as the documentation suggests that this is the only way that automatically refreshes tokens.
In my example, the user authenticates with Google, this then correctly creates a Federated Identity and populates a user in the User Pool. the Hub.listen correctly fires on the ‘signIn’ event in which I can console.log the current user.
The problem I’m having is that after 60 minutes, the session and token expires. The documentation suggests that Amplify should “magically” handle the token refresh in the background, but this does not happen.
I am able to console.log the Hub.listen event which gives "The OAuth redirect failed to be parsed"
Sample code
import React, { Component } from 'react';
import { StyleSheet, Text, ScrollView, SafeAreaView, StatusBar, Button } from 'react-native';
import { withOAuth } from "aws-amplify-react-native";
import Amplify, { Auth, Hub } from 'aws-amplify';
import config from './aws-exports'
Amplify.configure(config)
const oauth = {
// Domain name
domain: 'xxxxxx.amazoncognito.com',
// Authorized scopes
scope: ['email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
// Callback URL
redirectSignIn: 'amplifyauth://', // this is name of app which correctly redirects after sign in
// Sign out URL
redirectSignOut: 'amplifyauth://', // this is name of app which correctly redirects after sign out
// 'code' for Authorization code grant,
// 'token' for Implicit grant
responseType: 'token',
}
Amplify.configure({
Auth: {
oauth: oauth
}
});
class App extends React.Component {
constructor(props) {
super(props);
Hub.listen('auth', (data) => {
switch (data.payload.event) {
case 'signIn':
console.log('sign in success');
Auth.currentAuthenticatedUser().then(user => {
console.log(user);
this.setState({ authState: 'signedIn' });
}).catch(e => {
console.log(e);
this.setState({ authState: 'signIn' });
});
break;
case 'signIn_failure':
console.log('sign in failed');
break;
default:
break;
}
});
Auth.currentSession().then((session) => {
console.log('current session')
console.log(session.idToken.jwtToken);
});
}
render() {
const {
oAuthUser: user,
oAuthError: error,
googleSignIn,
signOut,
} = this.props;
return (
<SafeAreaView style={styles.safeArea}>
{user && <Button title="Sign Out" onPress={signOut} icon='logout' />}
<ScrollView contentContainerStyle={styles.scrollViewContainer}>
<Text>{JSON.stringify({ user, error, }, null, 2)}</Text>
{!user && <React.Fragment>
{/* Go directly to a configured identity provider */}
<Button title="Google" onPress={googleSignIn} />
</React.Fragment>}
</ScrollView>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
safeArea: {
flexGrow: 1,
paddingTop: StatusBar.currentHeight,
backgroundColor: '#FFFFFF',
},
scrollViewContainer: {
flexGrow: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
export default withOAuth(App);
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
React Native Firebase Social Auth doesn't work on release
We've tested on several phones. Email login works fine, only google auth doesnt work. Logcat doesn't show anything. I press the google button, ......
Read more >React Native does not persist login / sessions after app restart
I am following the Task Tracker tutorial and I am not able to persist the login session. I am able to register and...
Read more >Authentication | React Native Firebase
Persisting authentication state. On web based applications, the Firebase Web SDK takes advantage of features such as cookies and local storage to persist...
Read more >Authentication State Persistence | Firebase - Google
Indicates that the state will be persisted even when the browser window is closed or the activity is destroyed in React Native. An...
Read more >React Native Expo Firebase Facebook Login - YouTube
React, Firebase v9 Facebook authentication · React Native - Login with Twitter · React Native, Firebase Google authentication - Android · Facebook ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@matthieunelmes did you enable the flow in your web client setting?
This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.