简体   繁体   中英

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

I am trying to use Laravel socialte plugin to login user using popup. So, during callback I am using scripts to call parent window function. But, its never called because, auth()->login() function redirects to home page as soon as its called. How do I stop this redirection?

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;
}

You can manually login the user:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM