Local Storage Error on Login in react native

I’m using moralis verison 0.0.183 and react-moralis version 0.3.11. I’m trying to do a simple email password login with

const login = async () => {
      try {
        const curr_user = await Moralis.User.logIn(userEmail, userPassword, { usePost: true });
        navigation.navigate("Camera");
      } catch (error) {
        const code = error.code;
        const message = error.message;
        setLoginError(true);
        setErrorText(message);
      }
    }

However, when I do I get an error saying can’t find variable localStorage. So I added the following lines

const Moralis = require('moralis/react-native.js');
const AsyncStorage = require('react-native').AsyncStorage;
Moralis.setAsyncStorage(AsyncStorage);

But still getting the same error, any ideas?

1 Like

the team on moralis just put up a video relating to your issue. not sure why you getting a localstorage error. its probably some behind the scenes stuff moralis does to detected acgive users by logging an acount or active state to local storage. i cant say for sure tho. this guid will help youl solve your problem. login with email/password is made easy with moralis

1 Like

Hey thanks for your help. However, I’m trying to do email password authentication

Based on your error seems like if it’s using local storage, then it might not be possible to use it on mobile :thinking:, I think mainly coz the function was designed to be usable on web browser first. It might be an added feature in the future, if you like to appreciate it to make a GitHub issue/featuee request on this :raised_hands:

1 Like

Thanks for the reply, but looking here: https://github.com/MoralisWeb3/Moralis-JS-SDK. It seems like local storage is supposed to be used on react native. I’m not sure what the feature request would be.

I just googled yest it is, but the implementation is a bit different, in web browser it uses window.localStorage or something like so, but seems like RN has a modified implementation in AsyncStorage. If you are not sure what feature request to add, you can raise awareness to the devs on the error you had :raised_hands:

Whats the best way to raise awareness to the devs?

If you really have no idea, just explained the context of what you’re doing, give some code, and the error that you get :raised_hands: that should be sufficient

there is a forum thread specific to react native boilerplate: Ethereum React Native Boilerplate Questions