Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. googleSignIn = async () => {
  2.     try {
  3.       const result = await Expo.Google.logInAsync({
  4.         androidClientId: '357293954753-g443nr53jcd34dajt46u5b20265jq1do.apps.googleusercontent.com',
  5.         scopes: ["openid", "profile", "email"]
  6.       })
  7.       if (result.type === "success") {
  8.         console.log(result)
  9.         this.props.parent.setState({
  10.           isLoading: true,
  11.         });
  12.         fetch(this.props.host_address + '/authorize', {
  13.           method: 'POST',
  14.           headers: {
  15.             Accept: 'application/json',
  16.             'Content-Type': 'application/json',
  17.           },
  18.           body: JSON.stringify({
  19.             idToken: result.idToken,
  20.             accessToken: result.accessToken
  21.           }),
  22.         }).then((response) => {
  23.           if (response.ok) {
  24.             // console.log(response);
  25.             response.json().then((responseJson) => {
  26.               // console.log(responseJson.api_key);
  27.               this.props.parent.setState({
  28.                 api_key: responseJson.api_key,
  29.                 isLoading: true,
  30.                 isLoggedIn: true
  31.               });
  32.               this.props.parent.refresh();
  33.               try {
  34.                 await AsyncStorage.setItem('api_key', responseJson.api_key);
  35.               } catch (error) {
  36.                 // Error saving data
  37.               }
  38.             });
  39.           }
  40.         }).catch((error) => {
  41.           console.error(error)
  42.         });
  43.       } else {
  44.         console.log("cancelled")
  45.       }
  46.  
  47.     } catch (e) {
  48.       console.log("error", e)
  49.     }
  50.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement