У меня нормально работает логин Android, но по какой-то причине мой логин iOS, похоже, не подключается и не проходит через него. Я использую React-native-secure-key-store для iOS
Вероятно, все работает, и я не выкидываю никаких ошибок, поэтому не могу понять, в чем проблема. Любое руководство будет с благодарностью.
import React, {Component} from 'react';
import {TextInput, TouchableHighlight, Modal, Button, Platform, StyleSheet, Text, View, Image} from 'react-native';
import {createStackNavigator, createDrawerNavigator} from 'react-navigation';
import RNSecureKeyStore from "react-native-secure-key-store";
import AccountManager from 'react-native-account-manager';
async checkAuthentication(){
if(Platform.OS == 'android'){
// check if token exists for android
AccountManager.getAccountsByType('Test').then((accounts) => {
if(accounts.length > 0){
AccountManager.getUserData(accounts[0], 'key').then((token) => {
console.log("RAW JSON retreived", token);
this.getUserInfo(token.value);
});
}
})
}
else{
if(Platform.OS == 'iOS'){
// check if token exists for iOS
RNSecureKeyStore.ACAccountCredential('Test').then((accounts) => {
if(accounts.length > 0){
RNSecureKeyStore.getUserData(accounts[0], 'key').then((token) => {
console.log("RAW JSON retreived", token);
this.getUserInfo(token.value);
});
}
})
}
}
}
async authenticate(){
try{
var formData = new FormData();
formData.append('grant_type', 'password');
formData.append('client_id', 2);
formData.append('client_secret', '$1test234873489ufdjahfha87953hfd');
formData.append('scope', '*');
formData.append('username', this.state.username);
formData.append('password', this.state.password);
let response = await fetch('https://test.direct/oauth/token', {
method: 'POST',
headers: {
Accept: 'application/json'
},
body: formData
});
let responseJson = await response.json();
console.log(JSON.stringify(responseJson));
if(Platform.OS == 'android'){
AccountManager.addAccountExplicitly('Test', this.state.username, this.state.password)
.then((account) => {
console.log('account successfully added', account)
AccountManager.setUserData(account, 'key', responseJson.access_token);
this.getUserInfo(responseJson.access_token);
}).catch((e) => {
console.log('fail to add account', e);
});
}
else{
// Pauls iOS storage token
// For storing key
if(Platform.OS == 'iOS'){
RNSecureKeyStore.ACAccountStore('Test', this.state.username, this.state.password)
.then((account) => {
console.log('account successfully added', account);
RNSecureKeyStore.set(account, 'key', responseJson.access_token);
}, (err) => {
console.log('account set', err);
});
// For retrieving key
RNSecureKeyStore.getUserInfo(responseJson.access_token)
.then((account) => {
console.log(('account successfully retrieved', account));
}, (err) => {
console.log('fail to retrieved account', err);
});
}
}