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

    WHERE IS MAIN.JS IN QUASAR?

    Help
    3
    4
    5981
    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.
    • M
      MathSilva last edited by Shone

      I am calling an action with VUEX and i check if user is authenticated in the life cycle CREATED through main.js with vue without quasar

      created() {
       this.$store.dispatch('loadUserData'),
        firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
          // add user into the store 
        }
      });
      
      }
      

      What can i do to call some action in quasar when all my application start, since these current versions there is not the main.js
      #quasar #doubt

      1 Reply Last reply Reply Quote 0
      • Shone
        Shone last edited by Shone

        @MathSilva You don’t need main.js with Quasar. As it said in Quasar docs

        For initialization code and importing libraries into your website/app, read about App Plugins.

        Read this also quasar.conf.js

        M 1 Reply Last reply Reply Quote -1
        • M
          MathSilva @Shone last edited by

          @shone i have read that, acctually all the documentation, but how can i call an action when the whole application starts? I was doing that with main of vue it was working fine. But i need to do it in quasar. I mean i don’t want to call this action when a single component loads, cuz i could call it directly in the component, but in the whole application.

          1 Reply Last reply Reply Quote 0
          • Z
            zeidanbm last edited by

            I haven’t used firebase before and not sure what best practices are for using firebase, but it appears you are trying to check authentication before your main component is created. Again as I have not used firebase, what I would do with a regular spa jwt is to take all auth logic and set it in an app plugin. you can read more about this in quasar docs. Then I would set another plugin for my routerHooks (utilise beforeRouteEnter to check for auth and redirect accordingly) so this would serve as an auth middleware.

            To create an app plugin you need to first create a file in plugin folder either manually or using quasar cli(recommended)

            // first import firebase and whatever you need
            export default ({ app, router, store, Vue }) => {
              // add your code here to check for auth user and interact with store
            }
            

            Next you need to make sure you register the plugin in quasar.conf (refer to docs).

            Another way this can be done is to use the preFetch feature, check it out maybe it helps.

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