4

In React Native how to Store values in session ?

I need to store login details (Username , Password) in session .

Could you Please Give any ideas.

0

1 Answer 1

19

Use AsyncStorage.

Example:

For saving:

AsyncStorage.multiSet([
    ["email", userInfo.email],
    ["name", userInfo.name]
])

For Deleting:

let keys = ['email', 'name'];
AsyncStorage.multiRemove(keys, (err) => {
    console.log('Local storage user info removed!');
});

For Getting:

AsyncStorage.multiGet(['email', 'name']).then((data) => {
    let email = data[0][1];
    let name = data[1][1];

    if (email !== null)
        //Your logic
});
Sign up to request clarification or add additional context in comments.

2 Comments

AsyncStorage saved data in unencrypted form and is accessible globally. so Its not the best option to save password
@RaheelHasan can we not encrypt them before storing to AsyncStorage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.