Im trying to login my users through facebook and twitter, the validation process is in the API, so i show the facebook (or twitter) login page and when the user make the login whit his credentials, the API returns the token.
The problem is when im try to test in Android, dont make the redirect to the main view. I was reading and say that maybe is how i injected the javascript code, but nothing seems to work.
Then was thinking that maybe is the uri scheme in the AndroidManifest, the problem is that the callback url is something like this:
http://ciudad-facil.perceptum.cl/callback/facebook?code=AQDtuj5zh0dCUDLG2akn5tomvwUK53GQEmpS9pOkl49JKRLyu92UHAP21XsKPhBUkii--pD5yW66K5mfPx_cxz3-bYRxEQOveiHvHMdtYD2RLCHJVEdig04dj3QtVVRQvXDHV0ym18Iyua-IWJEdwNA_cy1liQnDxAcFxPw7mtGiVGcmZVkEf0Wv4VzujocPjiLLJR6bdvV5neQYjJD9mcOeM6V4NUoegIGymt735Oag8CFWret-7rQ6xas2J4ZKztd_POl6u93aPUusHbonFxGvPMfKuUXiwbB64gIi_eI_AWIKowBWH6a0hUp3AxjvDuU&state=OVzqhRIJaemJYaVRvgqNTZ7i2A4f6zc6UGbdXpbl#=
but in the scheme i got something like this:
<data android:host="www.ciudad-facil.perceptum.cl"
android:pathPrefix="/callback/facebook"
android:scheme="http" />
But is not working, this is the code that im using for show the page to the user:
_onMessage = ( event ) => {
console.log('entro');
var response = event.nativeEvent.data;
if (response != '') {
response = JSON.parse(response);
console.log(response);
try {
AsyncStorage.setItem('auth_token', response.token);
AsyncStorage.setItem('created_user', (response.created).toString());
global.auth_token = response.token;
} catch (error) {
console.log('AsyncStorage error: ' + error.message);
}
Actions.Main();
}
}
render() {
var jsCode = "window.postMessage(document.getElementsByTagName('PRE')[0].innerHTML)";
return (
<WebView
source={{ uri: this.state.authUrl }}
onMessage={this._onMessage}
injectedJavaScript={jsCode}
startInLoadingState={true}
/>
);
}
PD: In iOS this works perfectly. The problem is just Android
This is for everyone, that pass through the same. The solution is:
First of all, set the scheme on your AndroidManifest, example:
<data android:host="www.xxxxx.com"/>
Then, when you are using Android, the form of inject the JS code is with:
window.__REACT_WEB_VIEW_BRIDGE.postMessage(....)
So yeah, thats the solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With