簡體   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