Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- googleSignIn = async () => {
- try {
- const result = await Expo.Google.logInAsync({
- androidClientId: '357293954753-g443nr53jcd34dajt46u5b20265jq1do.apps.googleusercontent.com',
- scopes: ["openid", "profile", "email"]
- })
- if (result.type === "success") {
- console.log(result)
- this.props.parent.setState({
- isLoading: true,
- });
- fetch(this.props.host_address + '/authorize', {
- method: 'POST',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- idToken: result.idToken,
- accessToken: result.accessToken
- }),
- }).then((response) => {
- if (response.ok) {
- // console.log(response);
- response.json().then((responseJson) => {
- // console.log(responseJson.api_key);
- this.props.parent.setState({
- api_key: responseJson.api_key,
- isLoading: true,
- isLoggedIn: true
- });
- this.props.parent.refresh();
- try {
- await AsyncStorage.setItem('api_key', responseJson.api_key);
- } catch (error) {
- // Error saving data
- }
- });
- }
- }).catch((error) => {
- console.error(error)
- });
- } else {
- console.log("cancelled")
- }
- } catch (e) {
- console.log("error", e)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement