mercredi 15 novembre 2017

Laravel Ajax request, Auth:login returns false! but user is logged in after refresh

I want to log users in with ajax request and after login in controller, redirect users to dashboard with javascript.

The Problem is when I use Auth:login($user) in controller, it returns false and my return line in controller is not reached. when I refresh the page manually I see that user is logged in !!

Backend (pseudo code):

    $r = $request->all();
    $user = User::where('email', $r['email'])->first();

    Auth::login($user);  // this returns false


    return [  // this line is not reached
        'status' > 'success'
    ];

Front End :

$.ajax({
       type: 'Post',
       url: '/login/js-login',
       data: user_data,
       success: function (res) {
        if (res.data.status == 'success') {
         toastr.success(" LoginSuccessfull!")                             
         window.location.replace("https://www.example.com");
      } else {
         toastr.error('Error Login!')
      }

      });



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zZLhzz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire