Laravel app logging out authenticated user when redirecting (it shouldn’t)

I have created a method that logs a user into our site via a link from a separate website. We use a token and username to find the user, then use the built in login method to authenticate them (I can confirm this all works as expected).

Here is the function:

public function login($username, $token, $redirect)
{
$accountLogin = AccountLogin::Where('username', $username)
->Where('token', $token)
->first();

if ($accountLogin) {
try {
Auth::login($accountLogin);
print_r(Auth::check()) // prints 1.
header('Location: ' . $redirect);
exit;
} catch (Exception $e) {
return $e->getMessage();
}
}

echo(array(
'status' => 'error',
'message' => 'Error logging in'
));
}

My problem is that the user seems to be logged out after the redirect.

Within the function above I can see the the account is found, and Auth::check() returns 1 or if I echo out Auth::User() then I do get the users info.

We then attempt to do a redirect which should take us to the route passed in as a parameter (you do need to be authenticated for all these routes) but instead I am redirected to the home page and logged out. If I log in from that page then it takes me to the url I wanted to reach originally (so it’s like it is remembering where I want to go, but just doesn’t recognise that I’m logged in).

Both sites are currently running locally via apache.

TIA.

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/2Sr0YaD
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.