savannabits / acacia

Backend Code Generator for Laravel 9, Vue 3 and Tailwindcss 3 using primevue
https://acacia.savannabits.com
MIT License
41 stars 10 forks source link

After login, if the intended redirect is the backend it does not render, instead it stays on the login page. #20

Closed coolsam726 closed 2 years ago

coolsam726 commented 2 years ago

This might be due to the fact that the redirection is via inertia but the backend uses a different root view.

coolsam726 commented 2 years ago

This is the case only if you use Inertia - Vue stack for your breeze installation.

coolsam726 commented 2 years ago

This issue is not related to acacia. It is an inertia issue and the way to get around it is to use the default (blade) stack for inertia in your app and include this code on the AuthenticatedSessionController::create method:

public function create(Request $request)
    {

        if (\Request::inertia()) {
            return Inertia::location(url()->current());
        }

        return view('auth.login');
    }

If you must use the Vue-Inertia breeze stack, then instead of redirecting after login (store() function), you can do Inertia::location to force a full page load.

public function store(LoginRequest $request)
    {
        $request->authenticate();

        $request->session()->regenerate();

//        return redirect()->intended(RouteServiceProvider::HOME);
        $path = session()->pull('url.intended', RouteServiceProvider::HOME);
        return Inertia::location(url($path));
    }

The same rules apply on logout.