Laravel session destroyed on page refresh





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















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

use AppHttpControllersController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;

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.










share|improve this question

























  • It could be that the session is not persisted. Please check that the driver in config/session.php is not array. More info at laravel.com/docs/5.7/session

    – Adrian Hernandez-Lopez
    Nov 22 '18 at 11:53











  • In order to use Auth::user()->name you need to use the namespace Auth; e.g.: use Auth;

    – Patrick
    Nov 22 '18 at 12:02











  • @AdrianHernandez-Lopez driver is set as file : 'driver' => env('SESSION_DRIVER', 'file'), and the files are actually inside of the storage/framework/sessions folder.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:27













  • @Patrick I am using it already. That is not the problem because it is working the first time. I login, it redirects me to the admin page (and it displays the user name, so it's working fine). The problem is when I refresh the page or try to navigate to a different route, it appears to eliminate the session and redirects me to the login form again.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:30











  • Is there any special reason you don't use the default Auth::routes(); and the default LoginController generated when you run php artisan make:auth?

    – nakov
    Nov 22 '18 at 13:01


















0















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

use AppHttpControllersController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;

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.










share|improve this question

























  • It could be that the session is not persisted. Please check that the driver in config/session.php is not array. More info at laravel.com/docs/5.7/session

    – Adrian Hernandez-Lopez
    Nov 22 '18 at 11:53











  • In order to use Auth::user()->name you need to use the namespace Auth; e.g.: use Auth;

    – Patrick
    Nov 22 '18 at 12:02











  • @AdrianHernandez-Lopez driver is set as file : 'driver' => env('SESSION_DRIVER', 'file'), and the files are actually inside of the storage/framework/sessions folder.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:27













  • @Patrick I am using it already. That is not the problem because it is working the first time. I login, it redirects me to the admin page (and it displays the user name, so it's working fine). The problem is when I refresh the page or try to navigate to a different route, it appears to eliminate the session and redirects me to the login form again.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:30











  • Is there any special reason you don't use the default Auth::routes(); and the default LoginController generated when you run php artisan make:auth?

    – nakov
    Nov 22 '18 at 13:01














0












0








0








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

use AppHttpControllersController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;

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.










share|improve this question
















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

use AppHttpControllersController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;

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.







php laravel session laravel-5.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 15:19







Alejandro Otero Gómez

















asked Nov 22 '18 at 11:48









Alejandro Otero GómezAlejandro Otero Gómez

32




32













  • It could be that the session is not persisted. Please check that the driver in config/session.php is not array. More info at laravel.com/docs/5.7/session

    – Adrian Hernandez-Lopez
    Nov 22 '18 at 11:53











  • In order to use Auth::user()->name you need to use the namespace Auth; e.g.: use Auth;

    – Patrick
    Nov 22 '18 at 12:02











  • @AdrianHernandez-Lopez driver is set as file : 'driver' => env('SESSION_DRIVER', 'file'), and the files are actually inside of the storage/framework/sessions folder.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:27













  • @Patrick I am using it already. That is not the problem because it is working the first time. I login, it redirects me to the admin page (and it displays the user name, so it's working fine). The problem is when I refresh the page or try to navigate to a different route, it appears to eliminate the session and redirects me to the login form again.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:30











  • Is there any special reason you don't use the default Auth::routes(); and the default LoginController generated when you run php artisan make:auth?

    – nakov
    Nov 22 '18 at 13:01



















  • It could be that the session is not persisted. Please check that the driver in config/session.php is not array. More info at laravel.com/docs/5.7/session

    – Adrian Hernandez-Lopez
    Nov 22 '18 at 11:53











  • In order to use Auth::user()->name you need to use the namespace Auth; e.g.: use Auth;

    – Patrick
    Nov 22 '18 at 12:02











  • @AdrianHernandez-Lopez driver is set as file : 'driver' => env('SESSION_DRIVER', 'file'), and the files are actually inside of the storage/framework/sessions folder.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:27













  • @Patrick I am using it already. That is not the problem because it is working the first time. I login, it redirects me to the admin page (and it displays the user name, so it's working fine). The problem is when I refresh the page or try to navigate to a different route, it appears to eliminate the session and redirects me to the login form again.

    – Alejandro Otero Gómez
    Nov 22 '18 at 12:30











  • Is there any special reason you don't use the default Auth::routes(); and the default LoginController generated when you run php artisan make:auth?

    – nakov
    Nov 22 '18 at 13:01

















It could be that the session is not persisted. Please check that the driver in config/session.php is not array. More info at laravel.com/docs/5.7/session

– Adrian Hernandez-Lopez
Nov 22 '18 at 11:53





It could be that the session is not persisted. Please check that the driver in config/session.php is not array. More info at laravel.com/docs/5.7/session

– Adrian Hernandez-Lopez
Nov 22 '18 at 11:53













In order to use Auth::user()->name you need to use the namespace Auth; e.g.: use Auth;

– Patrick
Nov 22 '18 at 12:02





In order to use Auth::user()->name you need to use the namespace Auth; e.g.: use Auth;

– Patrick
Nov 22 '18 at 12:02













@AdrianHernandez-Lopez driver is set as file : 'driver' => env('SESSION_DRIVER', 'file'), and the files are actually inside of the storage/framework/sessions folder.

– Alejandro Otero Gómez
Nov 22 '18 at 12:27







@AdrianHernandez-Lopez driver is set as file : 'driver' => env('SESSION_DRIVER', 'file'), and the files are actually inside of the storage/framework/sessions folder.

– Alejandro Otero Gómez
Nov 22 '18 at 12:27















@Patrick I am using it already. That is not the problem because it is working the first time. I login, it redirects me to the admin page (and it displays the user name, so it's working fine). The problem is when I refresh the page or try to navigate to a different route, it appears to eliminate the session and redirects me to the login form again.

– Alejandro Otero Gómez
Nov 22 '18 at 12:30





@Patrick I am using it already. That is not the problem because it is working the first time. I login, it redirects me to the admin page (and it displays the user name, so it's working fine). The problem is when I refresh the page or try to navigate to a different route, it appears to eliminate the session and redirects me to the login form again.

– Alejandro Otero Gómez
Nov 22 '18 at 12:30













Is there any special reason you don't use the default Auth::routes(); and the default LoginController generated when you run php artisan make:auth?

– nakov
Nov 22 '18 at 13:01





Is there any special reason you don't use the default Auth::routes(); and the default LoginController generated when you run php artisan make:auth?

– nakov
Nov 22 '18 at 13:01












1 Answer
1






active

oldest

votes


















0














I solved the problem. It was just a rookie mistake. I had the Auth::logout() function in the href property of a link, thinking it would trigger when someone clicked it. Instead, it logged me out as soon as the page loaded, that's why there was a session just the first time.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430353%2flaravel-session-destroyed-on-page-refresh%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I solved the problem. It was just a rookie mistake. I had the Auth::logout() function in the href property of a link, thinking it would trigger when someone clicked it. Instead, it logged me out as soon as the page loaded, that's why there was a session just the first time.






    share|improve this answer




























      0














      I solved the problem. It was just a rookie mistake. I had the Auth::logout() function in the href property of a link, thinking it would trigger when someone clicked it. Instead, it logged me out as soon as the page loaded, that's why there was a session just the first time.






      share|improve this answer


























        0












        0








        0







        I solved the problem. It was just a rookie mistake. I had the Auth::logout() function in the href property of a link, thinking it would trigger when someone clicked it. Instead, it logged me out as soon as the page loaded, that's why there was a session just the first time.






        share|improve this answer













        I solved the problem. It was just a rookie mistake. I had the Auth::logout() function in the href property of a link, thinking it would trigger when someone clicked it. Instead, it logged me out as soon as the page loaded, that's why there was a session just the first time.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 15:20









        Alejandro Otero GómezAlejandro Otero Gómez

        32




        32
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430353%2flaravel-session-destroyed-on-page-refresh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?