Hello
Can somebody help me with this topic please?
import React, { Component } from 'react';
import {Image, Text, TouchableOpacity, View, Platform} from "react-native";
import {clientsIdArray, testClintIdArray} from '../constants/clientIDs'
import {styles} from "../styles/GoogleButtonStyle";
import I18n from 'ex-react-native-i18n'
import Expo from "expo";
const osName = Platform.OS;
const osVersion = Platform.Version;
const deviceId = Expo.Constants.deviceId;
const deviceName = Expo.Constants.deviceName;
let createTokenController = 'https://rony-dot-forigotron.appspot.com/token/create';
export default class CreateTokenIdController extends Component {
static navigationOptions = {
title: 'ToogleBoard'
};
constructor(props) {
super(props);
this.state = {
appIsReady: false,
jwt: ''
}
}
async componentWillMount() {
await I18n.initAsync();
this.setState({appIsReady: true});
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.GooglePlusStyle} activeOpacity={0.5}
onPress={signInWithGoogleAsync.bind(this)}>
<Image
source={require('../assets/googleBtn.png')}
/>
<Text style={styles.TextStyle}>Login Using Google</Text>
</TouchableOpacity>
</View>
);
}
}
async function signInWithGoogleAsync() {
try {
const result = await Expo.Google.logInAsync({
androidClientId: testClintIdArray[0],
iosClientId: testClintIdArray[1],
// Will have package name com.ispcloudservices.toogleboard.mobile
androidStandaloneAppClientId: clientsIdArray[0],
iosStandaloneAppClientId: clientsIdArray[1],
webClientId: clientsIdArray[2],
scopes: ['profile', 'email'],
});
if (result.type === 'success') {
let responseJson = {
'domainName': 'ispcloudservices.com',
'userEmail': result.user.email,
'userToken': result.accessToken,
'userName': result.user.name,
'osName': osName,
'osVersion': osVersion,
'deviceId': deviceId,
'deviceName': deviceName,
'langId': I18n.locale
};
let formBody = [];
for (let property in responseJson) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(responseJson[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
let postData = {
method: 'POST',
headers: {
'User-Agent': 'ToogleBoard',
'referer': 'https://toogleboxmobile.com',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: formBody
};
fetch(createTokenController, postData)
.then((response) => response.json())
.then((responseJson) => {
this.setState({jwt: JSON.parse(responseJson.response).tokenId})
Expo.setItemAsync('key', this.state.jwt);
})
} else {
return {cancelled: true};
}
} catch (e) {
return {error: true};
}
}
As you can tell, I am login to google perfectly and generating the jwt (Json wet token), but I need to save that in secure storage. What I am trying to do is check the storage to see if I have the token if I do I present my other screen