Troubleshooting unexpected behavior with Custom Guest middleware in Nuxt Project

I have implemented the Nuxt auth module for my project. To manage the login page, I created a custom middleware called guest.js, which has the following code:

export default function ({ $auth, store, redirect }) {
    if (!process.server) {
     if ($auth.$state.loggedIn) {
             return redirect('/')
           }
      }
  }

In the Login component, I have specified the middleware as 'guest'.

The issue arises when the page is refreshed, as the server-side user status in the auth module is set to false:

{ user: null, loggedIn: false, strategy: 'local' }

I added a small check for this, but it seems that the middleware runs only on the server side during refresh. I am using Universal mode for Nuxt.

How can I make this work effectively?

Thank you.

Answer №1

The phrase if (!process.server) is now outdated as middlewares are consistently on the server side when utilized in a universal context. This has been recently updated.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS and CodeIgniter collaborating to bring server-side pagination

I am currently working on integrating pagination using AngularJS and CodeIgniter. The current implementation requires fetching all records at once. However, I aim to modify it so that the data can be retrieved one page at a time from the server during run ...

Angular2's $compile directive functions similarly to AngularJS 1's $compile directive

I am currently in the process of migrating my project from Angular 1 to Angular 2 and I am in need of a compile directive. However, I am struggling to rewrite it to achieve the same functionality as before. app.directive("compile", compile); compile.$inje ...

The posenet TensorFlow model results in Node.js do not contain any position detail for coordinates "x" and "y"

I executed the posenet model on node v8.11.0. Below is the code snippet that I utilized. Unfortunately, the output results are not displaying the position of each pose; instead, it simply shows [Object]. It seems like there might be a canvas-related issue. ...

Differences between Vue.js Composition API and Options API - utilizing posts ref within a v-for iteration

I am relatively new to working with VueJS, and I am facing a challenge that has me stumped. On a page that fetches data using axios from my posts on a wordpress site: export default { data() { return { postsUrl: "https://localhost/wordpre ...

Troubleshooting: Magento checkout page keeps scrolling to the top

We are experiencing an issue where, during the one page checkout process, the next step is not automatically scrolling to the top of the page when it loads. After a user fills out all their billing information and clicks continue, the next step appears ha ...

Error: protractor encountered an unexpected issue

Currently, I am following this tutorial I went through all the steps mentioned in the tutorial except for what was suggested in this post instead of npm install -g protractor I opted for npm install -g protractor --no-optional So far, I have succe ...

What are some ways to prevent sorting and dragging of an element within ul lists?

A list styled with bullets contains various items. It is important that the last item in the list remains in a fixed position. I attempted to disable sorting using the cancel option of the .sortable() method, but it only prevented dragging without disablin ...

Is there a way to determine the quantity of lines within a div using a Vue3 watcher?

Is it feasible to determine the number of text lines in a div without line breaks? I am looking to dynamically display or hide my CTA link based on whether the text is less than or equal to the -webkit-line-clamp value: SCRIPT: const isExpanded = ref(true ...

Javascript program that generates drag and drop elements using HTML5 features:

Whenever I attempt to drag and drop elements that are normally created by HTML, everything works fine. However, when I try to drag and drop elements generated by JavaScript, I encounter the following error: Uncaught TypeError: Cannot read property 'p ...

Function in Typescript that accepts either a single object or an array of objects

We frequently use a simple function declaration where the function can accept either a single object or an array of objects of a certain type. The basic declaration looks like this: interface ISomeInterface { name: string; } class SomeClass { pu ...

Nuxt.js | Issue with accessing property from computed method's return object

I have been using the computed method to dynamically assign variables and load my page. I am able to display the entire object, but encountering an issue when trying to display a single property. The error message that I receive is: Cannot read property ...

QUASAR: The functionality of redirecting using "push" is not functioning as expected

Hello there. I'm currently working on a file named "pages / Login.vue". Here is the form: View simple form <template> <div> <q-form @submit="btnlogin"> <q-input v-model="user" type="text" lab ...

The Vue user object appears to be null in spite of being defined and clearly visible in the log output

There seems to be an issue with my function that utilizes a person's user name to retrieve the current User from the database. Initially, when I log the current user within the function, everything works perfectly. However, once I attempt to access it ...

I am unable to align the image in the center, what could be causing it not to center properly?

Why does my code center in mobile view but not in Desktop? How can I solve this issue? I have tried using display: block; margin: auto; width:100%; and text-align: center;, but it did not work. let $slides, interval, $selectors, $btns, currentIndex, ne ...

Changing the depth buffer in a Three.js Shader Material

While working with Three js, I have implemented a vertex shader to animate a large geometry. Additionally, I have incorporated a Depth of Field effect into the output. However, I am encountering an issue where the Depth of Field effect does not seem to re ...

chaotic telerik editor arrangement

I have incorporated the Rad Editor into my ASP.NET page. <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <telerik:RadEditor ID="reSummery" runat="server" > </telerik:RadEditor> Despite not referencing ...

The absence of the iframe in ie8 is causing problems that cannot be fixed with relative positioning

On a website, I am integrating an external 2-factor authentication solution called Duo Web using their PHP and Javascript. It works smoothly on all browsers except for IE8. When the user passes the initial login screen, the 2FA login page loads, but the if ...

Transfer the script from package.json to an npm package

In each of our plugins' root directories, there is a file named tools.js. This file contains a build function that assists in creating builds for the plugin. The package.json file references it like this: "scripts": { "build:node&qu ...

Struggling to make image uploading function with Flask and JQuery

Utilize the code snippet below to submit forms and retrieve a modified version of text from Flask using AJAX and JQuery: from flask import Flask, render_template, request, jsonify app = Flask(__name__) @app.route('/') def index(): return re ...

I am interested in having the push notification feature function specifically for registered users

In an attempt to register the device for push notification using the PhoneGap plugin, I am encountering an issue. After the AJAX success action is called, the registration action does not alert the registration ID. Can someone help figure out what's g ...