nuxt-modules / strapi

Strapi Module for Nuxt
https://strapi.nuxtjs.org
MIT License
646 stars 81 forks source link

Error: A webpage is slowing down your browser what would you like to do #43

Closed baermathias closed 4 years ago

baermathias commented 4 years ago

Version

@nuxtjs/strapi: v0.1.6 nuxt: v2.14.0

Reproduction Link

I don't have one yet

Steps to reproduce

I have the following pages/routes in my setup: login/index.vue - to log the user in dashboard/index.vue - which can only be seen by logged-in users register/onboarding.vue - which should be redirected to, if the registration process is incomplete

I have configured middleware/auth.js as follows to force the user to complete the registration process if registrationComplete is false:

export default function ({ redirect, $strapi }) {
  // default condition (example from https://strapi.nuxtjs.org/usage)
  if (!$strapi.user) {
    return redirect('/login')
  }

  // DEBUG
  console.log('$strapi.user.registrationComplete', $strapi.user.registrationComplete)

  // custom condition 
  if (!$strapi.user.registrationComplete) {
    return redirect('/register/onboarding')
  }
}

Then I use middleware: 'auth' on the dashboard/index.vue and register/onboarding.vue page.

What is Expected?

I expect to be redirected to the onboarding page if the users flag registrationComplete is false

What is actually happening?

I get an error from the browser: A webpage is slowing down your browser what would you like to do? Stop/Wait Inside the browser console I can see from the debug line above that console.log('$strapi.user.registrationComplete', $strapi.user.registrationComplete) gets into an endless loop and is executed thousands of times! If I remove my custom condition inside auth.js, it gets out of the endless loop. What is happening here?

baermathias commented 4 years ago

My fault, had to remove middleware: 'auth' from the onboarding page, because it was redirecting it to itself.