繁体   English   中英

将access_token存储在AsyncStorage中

[英]Store access_token in the AsyncStorage

用户输入IDpassword ,我将从Rails传递access_token

我正在使用itzikbenh / Rails-React-Authitzikbenh / React-Native-Rails

但是我无法保存access_token 这是代码:

let res = await response.text();
if (response.status >= 200 && response.status < 300) {
    //Handle success
    let accessToken = res;
    console.log(accessToken);
    //On success we will store the access_token in the AsyncStorage
    this.storeToken(accessToken);
    //this.redirect('home');
    alert(ACCESS_TOKEN )
} else {
    //Handle error
    let error = res;
    throw error;
}

您可以使用AsyncStorage.setItem存储单个项目:

import { ... AsyncStorage } from 'react-native'

try {
  await AsyncStorage.setItem('access_token', access_token);
} catch (error) { // Error saving data }

然后使用AsyncStorage.getItem来检索它:

try {
  const value = await AsyncStorage.getItem('access_token');
  if (value !== null) console.log(value)
} catch (error) { // Error retrieving data }

有关存储和检索多个项目的信息,请参见AsyncStorage.multiSetAsyncStorage.multiGet

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM