Why not just no allow the login route for logged in users. That way you avoid ever having the situation you are describing.
L5 - CSRF Token Refresh Approach
All
I've noticed that for some reason sometimes you will get a CSRF token mismatch if you are already logged in and you are attempting to auth again. The form generates a new token, but as you are logged in the form's new token does not match the existing session token id.
Also, a logout followed by a login will not work as the form becomes the old token and then your session is the new token ... lol
Note I have "guest" as middleware on the controller
So I wonder if there is some sort of method to fix this. The only way I can think to is to remove all middleware auth related checks for login and then basically, check if the user is already authenticated, if so log them out and then log them in. The problem is I dont think this works as you need some sort of redirect to sync tokens.
Ideas?
Middleware joy ... lol
/**
* @Middleware("guest", except={"logout"})
* @Controller(prefix="auth")
*/
class AuthController extends Controller {
/// rest of controller logic
/**
* Handle a login request to the application.
*
* @Post("login", as="postAuthLogin")
* @Middleware("csrf")
*
* @param LoginRequest $request
* @return Redirect|\Illuminate\View\View
*/
public function getLogin(LoginRequest $request)
if(! $this->auth->check()) {
$this->auth->logout();
}
$authAttempt = $this->auth->attempt($request->only('email', 'password'));
/// rest of login
}
Please or to participate in this conversation.