Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+13 votes

Does anyone know how redirect pages in react after using Google Authenticator to login?

asked in CSC490_Spring202021 by (-499 points)
edited by
+3

Can you post some of the code that you are using, and a more specific explanation about what goes wrong? Are you seeing errors/error messages? If so, what are they?

+1

I'm not sure about what part the code I should share but, I am just having a hard time redirecting the user to (<App/>) once the user has been authenticated using their google account.

1 Answer

+5 votes

So I have a bit of code in react-native that needs to wait for a font to load before displaying a page. I have two different returns in my render method depending on if the app

async componentDidMount() {
  await Font.loadAsync({
     Roboto: require('native-base/Fonts/Roboto.ttf'),
     Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
     ...Ionicons.font,
  });
  this.setState({ isReady: true });
}

So in the componentDidMount() method I wait for the font to finish loading before changing the state of the app to say it is ready.

  render() {
  //Checks to see if the font loaded, if it has not it displays a temp screen
  if (!this.state.isReady) {
    return <View></View>
  }

So if the state is not ready I return a blank screen (could definitely be better). Then once the app is ready, I return the actual proper view with the loaded fonts:

render() {
  //Checks to see if the font loaded, if it has not it displays a temp screen
  if (!this.state.isReady) {
    return <View></View>
  }
  return (
    <NavigationContainer>
      <Stack.Navigator>
.....

I hope this helps!

answered by (1 point)
+2

That is interesting, I will try it and get back to you!

...