Obtaining tokens from async storage as null
See original GitHub issueYou want to:
I want to get token for setting up automatic login in my react native app. I have written getTokens
and setTokens
functions as shown below:
export const getTokens = (cb) => {
AsyncStorage.multiGet([
'@NBA_App@token',
'@NBA_App@refreshToken',
'@NBA_App@expireToken',
'@NBA_App@uid'
]).then(values => {
cb(values);
})
}
export const setTokens = (values, cb) => {
const dateNow = new Date();
const expiration = dateNow.getTime() + (3600* 1000)
AsyncStorage.multiSet([
['@NBA_App@token', values.token],
['@NBA_App@refreshToken', values.refToken],
['@NBA_App@expireToken', expiration.toString()],
['@NBA_App@uid', values.uid]
]).then(response => {
cb();
})
}
Details:
I am not able to get the tokens on reloading app using componentDidMount. I get the token array as ‘null’.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Obtaining tokens from async storage as null - Stack Overflow
I want to get token for setting up automatic login in my react native app. I have written getTokens and setTokens functions as...
Read more >How to use the react-native.AsyncStorage.setItem function in ...
To help you get started, we've selected a few react-native.AsyncStorage. ... Set token in AsyncStorage + memory await AsyncStorage.setItem('api/token', res.
Read more >How to use getItem function in AsyncStorageStatic - Tabnine
User Authentication (async () => { try { const token = await AsyncStorage.getItem('token') if (token && token !== 'undefined' && token !==
Read more >AsyncStorage - React Native
AsyncStorage is an unencrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of ...
Read more >A guide to React Native's AsyncStorage - LogRocket Blog
The getItem() method allows us to get data back from AsyncStorage by using the key the data was saved as. For example, assuming...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks like you’re using a very old version of React Native, and you’re using the included version of Async Storage. You’re not using this module at all, so we can’t really help you.
https://github.com/lopeselio/React-Native-NBA-app … I did proceed further and implemented the auto-login for the app.