0

I have been struggling with this error for 2 weeks. Project setup is basically simple:

  • docker-compose for building app, redis and mariadb containers
  • nginx on production server for serving app and build assets from react

After a while, especially while submitting login or any POST request handling from react jsx template (using inertia router.post method), it opens up a new window inside current one with redirect.

Here is my login controller method

public function login(Request $request)
{
    $credentials = $request->validate([
        'email' => 'required|email',
        'password' => 'required',
    ]);

    if (Auth::guard('client')->attempt($credentials, $request->boolean('remember'))) {
        $client = Auth::guard('client')->user();

        if ($client->status) {
            $request->session()->regenerate();

            return Inertia::location(route('client.admin'));
        }

        Auth::guard('client')->logout();

        throw ValidationException::withMessages([
            'email' => 'Your account is inactive.',
        ]);
    }

    throw ValidationException::withMessages([
        'email' => 'The provided credentials do not match our records.',
    ]);
}

Attaching screenshots:

plaintext JSON output of login form followed by "Redirecting to"

login form with "Email" and "Password" fields, "Remember me" checkbox, and "LOG IN" button

I would appreciate any help in resolving this. Thanks.

1
  • 2
    Please do NOT reveal your admin password in SO. Commented Oct 1 at 1:02

1 Answer 1

0

As document suggest Inertia::location is for redirect to an external location. Mean it will open a new window.

This method is mostly useful when any one want to redirect to external website.

For your case, use redirect()->route('client.admin') laravel build in redirect method.

Sign up to request clarification or add additional context in comments.

3 Comments

I replaced all Inertia::location logic with redirects but after a while still getting same problem. Also sometimes api endpoints return plain html with object instead of json.
What do you mean by "but after a while still getting same problem". Did it work for some amount of time or it never worked???? Did you try to clear browser and laravel cache???? And api endpoints is different issue not related to this.
It worked. After few hours when i logged out and wanted to login using different account credentials same problem occured.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.