0

I am tying to add authentication to routes using getUserConfirmation of "react-router-native", But getUserConfirmation is never getting called. I couldn't find much documentation on it as well.

const getConfirmation = (message, callback) => {
  //Here i will replace below code with authentication check
  Alert.alert('Confirm', message, [
    { text: 'Cancel', onPress: () => callback(false) },
    { text: 'OK', onPress: () => callback(true) }
  ])
}

<NativeRouter getUserConfirmation={getConfirmation}>
......
</NativeRouter>
Pram
  • 2,383
  • 2
  • 19
  • 21

1 Answers1

1

Though i didn't find proper example from reacttraining.com, after spending some time i found a way.

const getConfirmation = (message, callback) => {
    // auth code to authenticate before entering route
    requireRouteAuth({props:{history}}, callback);
}

<NativeRouter getUserConfirmation={getConfirmation}>
    ......
    <Prompt when={true} message={location => "message"}/>
</NativeRouter>

We need to attach component. Since i need auth on all routes when={true}.

Pram
  • 2,383
  • 2
  • 19
  • 21