Nuxt js using laravel passport redirects to login page after page refresh on secured pages - Fix

While I have seen a lot of people online have this issue since like around the year 2018 - there has not been a lot of helpful materials around this majorly because it's very difficult to track down because no error is reported.

We decided to migrate our Nuxt Js app at WATU from SPA to Universal and we started noticing this error. It's worth mentioning that WATU is a multi domain solution with different product available either as a root domain platform or a sub domain platform.

Having tried a lot of suggested solutions, I was finally able to track it down to the laravel routes. As this is a server rendered application, it turned out that we needed to add the protected routes to the laravel passport routes.

This is what we did below, under your api routes which can be found in routes/api.php , add the nuxt js domain accessing the laravel application API. Use the code below - make sure you format specifically for your own use case

$landingRoutes = function () {
//your routes
};
Route::group(['domain' => config('app.DASHBOARD_DOMAIN1')], $landingRoutes);
Route::group(['domain' => config('app._DASHBOARD_DOMAIN2')], $landingRoutes);

The reason why we used this method is because our application is a Multi domain solution and we need to define more than a single dashboard.

This method worked for me and I sincerely hope it does for you too.

PS:

This is my first blog post ever so kindly bear with me if you noticed anything amateurish.

No Comments Yet