Search code examples
ionic3ionic-storage

save to storage user input from AlertController


I basically have a to do list app, but to access the to do list, the user must enter a user name.

The project is in beta, so currently the user can enter any name and will be brought to the to do list.

I'm trying to take the next steps - I want the users to do list to be remembered.

For example, user enters "tim" as the user name, and all the to do items created under tim will be shown. User logs out, new username "lucy" is entered, all todo items created under lucy are shown. How can I do this?

I am currently saving the todo items to ionic storage, but now I want to save them to a username. Can anyone offer some guidance, or point me in the right direction?


Solution

  • You could still use storage for your storing purposes.

    In storage.set('tim',[array-of-todos])

    This will store a key under the name of Tim, and the array will contains all the todos of tim.

    And for Lucy you create another key and another array corresponding to the user Lucy.

    You can get the user by checking the entered username matches the key that you already stored.

    if(username === 'tim'){ storage.get('tim').then();}
    else{storage.get('lucy').then();}