I have an admin panel that I protect with user authentication. Once I try to access it, it redirects me to the login form, which uses the 'guest' middleware (this is the expected behaviour). Once I attempt to log in it works like a charm, redirects me to the admin dashboard and the Auth object is created (I can retrieve the name). However, if I click on any link inside of the panel, or press F5, it redirects me back to the login form. For the sake of testing what happened, I removed the 'auth' middleware protection from the admin panel, and it gives me an error when I try to retrieve the Auth::user()->name property.
Trying to get property 'name' of non-object
So I am assuming that it destroys the Auth object on every page refresh, what I don't understand is where this behaviour comes from. I am using the default Auth middlewares, with the LoginController provided in the documentation (with some tweaks):
<?php
namespace App\Http\Controllers\Authentication;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
public function authenticate(Request $request){
$email = $request->input('email');
$password = $request->input('password');
$remember = $request->input('remember');
if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
return redirect()->intended('dashboard');
}
}
public function index(){
return view('auth.login');
}
}
All of the routes in the admin panel are inside a group in my routes file:
Route::middleware(['auth'])->group(function () {
//All of the admin routes here
});
The login route is protected by the 'guest' middleware, so no authenticated user can access the login form.
Please ask me to post any code that you think could be helpful, I'm fairly new to Laravel and don't really know what to post.