在 laravel 中使用 auth()->login() 方法时如何防止重定向?

How to prevent redirection when using auth()->login() method in laravel?

我正在尝试使用 Laravel socialte 插件通过弹出窗口登录用户。因此,在回调期间,我使用脚本来调用父 window 函数。但是,它从未被调用,因为 auth()->login() 函数在调用后立即重定向到主页。如何停止此重定向?

public function handleProviderCallback($provider)
{
    $user = $this->createOrGetUser($provider);
    echo "<script>
    var Parent = window.opener;</script>";
    if(auth()->login($user)) {
        $tempuser = json_encode($user);
        $script = "<script>Parent.oauthSuccess(true,'$tempuser');</script>";
    } else {
        $script = "<script>Parent.oauthSuccess(false);</script>";
    }
    return $script;
    // $user->token;
}

您可以手动登录用户:

public function authenticate(Request $request)
{
    $credentials = $request->only('email', 'password');

    if (Auth::attempt($credentials)) {
        // Authentication passed...do something
    }
}

文档:https://laravel.com/docs/5.7/authentication#authenticating-users