I solved this problem by doing this:
_onLoad(state) {
if (state.url.indexOf(BASEURL + '/auth/success') != -1) {
let token = state.url.split("token=")[1];
token = token.substring(0, token.length - 4);
NavigationsActions.back();
NavigationsActions.replaceRoute({
id: 'your route id'
});
SessionActions.setSession(token);
}
}
I found a great tutorial that helps me understand how it works here .
This is what my whole component looks like:
import React, { Component } from 'react';
import {
StyleSheet,
WebView,
Text
} from 'react-native';
import NavigationsActions from '../../actions/NavigationsActions';
import NavigationConstants from '../../constants/NavigationConstants';
import RouteConstants from '../../constants/RouteConstants';
import SessionActions from '../../actions/SessionActions';
var BASEURL = 'http://localhost:8080';
class FacebookLogIn extends Component {
render() {
return (
<WebView onNavigationStateChange={this._onLoad} style={styles.container} source={{ uri: BASEURL + '/auth/facebook' }}/>
);
}
_onLoad(state) {
console.log(state.url);
if (state.url.indexOf(BASEURL + '/auth/success') != -1) {
let token = state.url.split("token=")[1];
token = token.substring(0, token.length - 4);
NavigationsActions.back();
SessionActions.setSession(token);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1
}
});
module.exports = FacebookLogIn;
source
share