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
    1. Home
    2. darshie
    D
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 9
    • Best 0
    • Groups 0

    darshie

    @darshie

    0
    Reputation
    67
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    darshie Follow

    Latest posts made by darshie

    • Router + vuex/vuex-persistedstate giving UnhandledPromiseRejectionWarning?

      I’m currently trying to clear some console bugs. One that is getting away from me: whenever I navigate to a requiresAuth page while not logged in, or whenever I navigate to the home page while logged in (I’ve set it to bounce away from home page when logged in), I get an UnhandledPromiseRejectionWarning. I’ve traced it to the Router. I’m running SSR app, and the error is happening on the server-side console.

      Heres’s the router/index.js:

      import Vue from 'vue'
      import VueRouter from 'vue-router'
      
      import routes from './routes'
      
      Vue.use(VueRouter)
      
      /*
       * If not building with SSR mode, you can
       * directly export the Router instantiation
       */
      
      export default function ({ store, ssrContext }) {
        const Router = new VueRouter({
          scrollBehavior: () => ({ x: 0, y: 0 }),
          routes,
      
          // Leave these as is and change from quasar.conf.js instead!
          // quasar.conf.js -> build -> vueRouterMode
          // quasar.conf.js -> build -> publicPath
          mode: process.env.VUE_ROUTER_MODE,
          base: process.env.VUE_ROUTER_BASE
        })
      
        Router.beforeEach((to, from, next) => {
          
          const currentUser = store.state.auth.user
          const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
      
          /* Something about this code below is creating a "UnhandledPromiseRejectionWarning"
          When I run either the game pages while not logged in or the splash page while logged in (essentially requiring redirection), the error triggers.
          */
      
          if (requiresAuth && !currentUser) next("/")
          else if (to.path == "/" && currentUser) next("/home/main")
          else next()
      
      
        });
      
        return Router
      }
      
      

      The exact error I’m getting is this:

      (node:6944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the
      CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

      I’m not really seeing a promise? This is likely my own oversight. Does anyone have any advice/feedback? Could this be something happening inside of the vuex-persistedstate boot file?

      Thanks, and HAPPY HOLIDAYS EVERYONE!

      posted in Help
      D
      darshie
    • RE: fixed tabs on top

      Hi,

      You could throw them into a QLayout Header with the appropriate view (capital H).

      You could also take a look at adding the positioning classes that suit your needs (fixed, fixed-top, etc.) to the element(s).

      posted in Help
      D
      darshie
    • RE: Loading firebase user identity before everything else?

      Okay… got it working with cookies–that’ll have to do for now.

      posted in Help
      D
      darshie
    • RE: Loading firebase user identity before everything else?

      I think this should work, but I’m getting the error

      UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): TypeError: local.getItem is not a function

      …and I don’t have the foggiest how to address it. Is it possibly because I’m using SSR? I don’t get that issue when running in SPA mode, but then, I don’t get any issues when running in SPA mode–my persistedstate / firebase properly loads before the page, so I don’t get re-directions on refresh.

      posted in Help
      D
      darshie
    • Loading firebase user identity before everything else?

      Currently doing a SSR app with Quasar v1 CLI & Firebase for auth (via Vuex). I have Firebase loaded in boot. Auth flow (simplified): if logged in, user can access anything under “player” layout (multiple pages). If not logged in, user can only see /login. Redirection accomplished via Router.beforeEach nav guard in router’s index.js.

      If just clicking links (router.push), everything works great. However, when reloading the page or trying to access an auth restricted page, it’ll bounce the logged-in user back to /login. From /login, clicking a nav link will work just fine again.

      I think the problem is on reload/URL entry, the entire state/js is wiped clean. List below of the fixes I tried. Long story short, though, I noticed that Firebase’s initial onAuthStateChange requests were returning null until the page fully loaded, and then user identity would be properly loaded to the state & returned. No matter how early I tried to tuck the Firebase listener into the flow, I got the same results. I thought it was Firebase’s problem until I followed Tobias’ suggestions link here for persistent storage via localstorage / cookies, and while I could get them working, my store.state.user.user wouldn’t update until redirection to /login had already occurred. Before then, store.state.user.user returned null. After, it properly read from localStorage.

      I’ve tried putting beforeCreated listeners on the relevant pages/layouts to get initial login state:

      mainAuthLayout.vue

      beforeCreate() {
        this.$auth.onAuthStateChanged(user => {
          if (user) {
            user.getIdToken().then(idToken => {
              this.$store.dispatch("user/setUser", idToken)
              this.$router.push("/home/main")
            })
          } else {
            this.$store.dispatch("user/setUser", null)
          }
        });
      }
      

      Didn’t work. I tried putting onAuthStateChange / getUser methods in the firebase boot file

      boot/firebase.js

      import firebase from "firebase/app"
      import "firebase/auth"
      import config from "./env.json"
      
      export const fireApp = !firebase.apps.length ? firebase.initializeApp(config) : firebase.app() 
      
      export const AUTH = fireApp.auth();
      
      export default ({ store, Vue }) => {
      
        AUTH.onAuthStateChanged(user => {
          if (user) {
            user.getIdToken().then(idToken => {
              store.dispatch("user/setUser", idToken);
            });
          } else {
            store.dispatch("user/setUser", null);
          }
        });
        
        Vue.prototype.$auth = AUTH;
      }
      

      That also didn’t work. I tried a pre-fetch on App.vue (basically the same code), which also didn’t work. In all of this the same problem: redirection to /login before store / $auth ever recognized that the user was already logged in.

      Incidentally:
      router/index.js

      Router.beforeEach((to, from, next) => {
        const currentUser = store.state.user.user
        const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
      
        if (requiresAuth && !currentUser) next("/")
        else next()
      })
      

      There’s no problem if I put my redirect logic as a .then(this.$router.push) in the pages themselves, but that is somewhat inelegant as it flashes the pages before redirection. Alternatively I could redirect users to a loading screen for a pretty short period of time which then routes them to the proper page once auth/store has had a chance to kick in, but I’d like to avoid if possible.

      Any help or directional feedback would be so welcome. Even just suggestions of where I could be looking / reading more. I’ve thrown 6 hours at this already, happy to throw more. Just wanted to see if any of you knowledgeable folks would be able to quickly spot something I was missing. 🙂

      posted in Help
      D
      darshie
    • RE: ClosePopup Error in beta 1.0.0

      @rstoenescu said in ClosePopup Error in beta 1.0.0:

      v-close-popup was added in quasar v1.0.0-beta.11.
      While we are in v1 beta, it is paramount that you are running latest version as soon as it is released.

      Turns out it was a silly mistake; this is exactly what was going on. Was on an earlier beta version. Thanks!

      posted in Help
      D
      darshie
    • RE: ClosePopup Error in beta 1.0.0

      Should note: using the Quasar CLI.

      posted in Help
      D
      darshie
    • ClosePopup Error in beta 1.0.0

      Hi,

      Beginner dev here. Running a vanilla Quasar SSR project. I’m trying to add v-close-popup to a dialogue button, but I can’t even get that far. The minute I add the ‘ClosePopup’ directive to the directives list in quasar.conf.js (as below):

        directives: [
          'ClosePopup',
          'Ripple'
        ],
      

      …running quasar dev -m ssr in the CLI will throw up an error (as below):

      Module build failed (from ./node_modules/babel-loader/lib/index.js):
      Error: Unknown import from Quasar: ClosePopup

      Remove the single ‘ClosePopup’ directive, and the app runs fine.

      Not sure if this is a bug or my inexperience showing in failing to catch a silly mistake. Any help appreciated.

      PS: confirmed I still get the same error running dev mode as SPA

      posted in Help
      D
      darshie