\n \u003C/div>\n\u003C/template>\n\n\u003Cscript>\nimport BulmaDashboard from \"@/components/SampleContent/BulmaDashboard\";\n\nexport default {\n middleware: \"auth\",\n layout: \"section\",\n fetch({ store, params }) {\n store.dispatch(\"user/getUser\")\n .then(() => console.log(\"user action dispatched\"));\n },\n components: {\n BulmaDashboard\n },\n mounted() {\n console.log(\"index mounted!\");\n }\n};\n\u003C/script>\n```\n\nauth/logout\n```javascript\nasync logout(vuexContext) {\n //if token is available, destroy it, needed so no loop is created (would return unauthorized which is then catched)\n //additionaly check if token already expired, wouldn't make sense requesting logout without valid token\n if (\n vuexContext.state.token &&\n new Date() \u003C new Date(vuexContext.state.tokenExpiry)\n ) {\n await this.$axios.get(\"/auth/logout.json\");\n }\n\n vuexContext.commit(\"CLEAR\");\n Cookie.remove(\"token\");\n Cookie.remove(\"tokenExpiry\");\n Cookie.remove(\"refreshToken\");\n Cookie.remove(\"refreshTokenExpiry\");\n Cookie.remove(\"userId\");\n\n //remove axios header\n this.$axios.setHeader(\"Authorization\", false);\n\n this.$router.replace(\"/login\");\n\n return \"[AUTH] Auth data cleared, safe to redirect\";\n }\n};\n```\n\n\n\n\n### What is expected ?\n\nWhen the user is not authenticated the initAuth action shoul be called which will redirect the user if there aren't any cookies or token is expired. No fetch() / asyncData() / mounted() functions should be called. \n\n### What is actually happening?\n\nThe user sees the page for a split second, it also fires fetch and mounted(), and then gets redirected.\n\nThe flow looks like this:\n\n[MIDDLEWARE] Not authenticated, reading data from cookie...\n[AUTH] No cookie files found , redirecting...\nindex mounted!\nfetch()\n\n### Additional comments?\n\nI've seen a similar issue like this here which is now resolved: https://github.com/nuxt/nuxt.js/issues/542\nWhen redirecting directly from the middleware everything works as expected, however when dispatching an action which in turn redirects, the problem described on this site still exists.\n\n\u003C!--cmty-->\u003C!--cmty_prevent_hook-->\n\u003Cdiv align=\"right\">\u003Csub>\u003Cem>This bug report is available on \u003Ca href=\"https://cmty.app/nuxt\">Nuxt\u003C/a> community (\u003Ca href=\"https://cmty.app/nuxt/nuxt.js/issues/c7469\">#c7469\u003C/a>)\u003C/em>\u003C/sub>\u003C/div>",[2062,2063],{"name":2026,"color":2027},{"name":1985,"color":1986},3618,"fetch/asyncData gets fired even when middleware redirects","2023-01-22T15:30:05Z","https://github.com/nuxt/nuxt/issues/3618",0.7458745,{"labels":2070,"number":2072,"owner":1988,"repository":1988,"state":1989,"title":2073,"updated_at":2074,"url":2075,"score":2076},[2071],{"name":1985,"color":1986},6332,"Emitting an event from middleware","2023-01-18T21:49:10Z","https://github.com/nuxt/nuxt/issues/6332",0.74645364,{"description":2078,"labels":2079,"number":2081,"owner":1988,"repository":1988,"state":1989,"title":2082,"updated_at":2083,"url":2084,"score":2085},"Hi,\r\n\r\nIm using middleware that checks auth. If its empty i will redirect user to login page with a message.\r\n\r\n```\r\nexport default function ({ store, redirect }) {\r\n if (!store.state.authUser) {\r\n store.commit('SET_NOTI', {\r\n type: 'warn',\r\n title: 'Login',\r\n message: 'You need to log in'\r\n })\r\n console.log(store.state.notiAfterRoute)\r\n redirect('/login')\r\n }\r\n}\r\n```\r\n\r\nBut after redirect by store is null ( the value it should be on start) . If i console log it before redirect. it returns a object like it should. \r\n\r\nI have tryed to solve this for couple of hours now. I tryed to use dispatch, promises everything.\n\n\u003C!--cmty-->\u003C!--cmty_prevent_hook-->\n\u003Cdiv align=\"right\">\u003Csub>\u003Cem>This question is available on \u003Ca href=\"https://nuxtjs.cmty.io\">Nuxt.js\u003C/a> community (\u003Ca href=\"https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1667\">#c1667\u003C/a>)\u003C/em>\u003C/sub>\u003C/div>",[2080],{"name":1985,"color":1986},1855,"Store is empty after redirect.","2023-01-18T15:42:45Z","https://github.com/nuxt/nuxt/issues/1855",0.748183,{"labels":2087,"number":2090,"owner":1988,"repository":1988,"state":1989,"title":2091,"updated_at":2092,"url":2093,"score":2094},[2088,2089],{"name":2026,"color":2027},{"name":1985,"color":1986},8009,"middleware redirect - params discarded","2023-01-22T15:36:08Z","https://github.com/nuxt/nuxt/issues/8009",0.7519181,["Reactive",2096],{},["Set"],["ShallowReactive",2099],{"TRc1wZytZ_XrK4EfJfei_Sz-An4H4Yy6syhVxH_PVJc":-1,"vhJtwfn9J3CYXsWftz0HoKsl46GfAGT4d94Pzky3QrU":-1},"/nuxt/nuxt.com/20"]