question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Obtaining tokens from async storage as null

See original GitHub issue

You 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’.

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tido64commented, Dec 9, 2020

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.

0reactions
lopeseliocommented, Dec 8, 2020

https://github.com/lopeselio/React-Native-NBA-app … I did proceed further and implemented the auto-login for the app.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found