No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Session/Local Variables for Quasar

    Help
    2
    4
    868
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      felice last edited by

      I am creating a login page for my application, and I was thinking how can I store my username as a session variable such that the username will be display on my pages after I have logged in.

      I have looked at the Local/Session Plugin from https://quasar.dev/quasar-plugins/web-storage#Introduction but was unclear of how I should implement it in my code.

      I have followed and used the code from the documentation in my <script> tag as shown:

      this.$q.localStorage.set(key, value)
      let value = this.$q.localStorage.getItem(key)
      

      This is a variable that I use to store the username from the username input textfield:

      var current_username = this.userToSave.username;
      

      Are there any examples I could reference to for the Local/Session Plugin? And if I used the above code in my login page, how can I access the session variable in my other pages?

      Would appreciate some help on this, thank you!

      1 Reply Last reply Reply Quote 0
      • F
        felice last edited by

        I have figured out how it works!

        At login page:

        this.$q.localStorage.set("username", current_username)
        

        At main page:

        let value = this.$q.localStorage.getItem("username")
        

        If I want to logout from my application, do I do the following?

        this.$q.localStorage.clear()
        
        1 Reply Last reply Reply Quote 0
        • J
          jraez last edited by

          If you clear the localStorage, you’ll remove all data, not only the username. It’s safer to use this.$q.localStorage.remove("username").
          I’ll advise you to use vuex instead, keep username in the store and use actions to login/logout/authenticate/etc.
          https://vuex.vuejs.org/

          F 1 Reply Last reply Reply Quote 0
          • F
            felice @jraez last edited by

            @jraez Oh, I see. Will try that, thanks alot for the help! 🙂

            1 Reply Last reply Reply Quote 0
            • First post
              Last post