Support the ongoing development of Laravel.io →
Authentication Session
Last updated 2 years ago.
0

You shouldn't need to put the value in the Session yourself, Laravel Authentication will take care of that.

Do you have a field called "ID" in your users table? Otherwise the attempt() method should fail because it uses ID to look for the user you are trying to login.

0

Thanks for your reply.

But the table has 'ID' field and Auth::attempt() succeeds to redirect to dashboard.

I can get user session data using Session::get('current_user').

If I don't put session value, how can I access user session data. Before doing that, I see not enough user data in session files under /storage/framework/sessions.

And Why Auth::user() returns NULL?

0

Hi guys!

I have the same problem :/

I set up a route like this:

Route::get('admin', ['middleware' => 'auth', 'uses' => 'Admin@index']);

I'm using the "built-in" user authentication.

When the process reaches the AuthenticatesUsers.php -> handleUserWasAuthenticated() function I dump out the $this->redirectPath() (which says: \home..) and I can see that it's trying to redirect me to http://localhost:8000/admin but I'm always getting back to http://localhost:8000/auth/login.

What am I doing wrong?

Meanwhile, in the routes.php I'm dumping out the Auth::user() and it always says null.

0

What are you using for hosting? Xampp? I think there was a problem with session cookies or something. That might be the actual problem.

0

I'm using wamp, but I don't understand that why can it be a problem. In laravel 5.0 wamp was fine to host the application. What changed in laravel 5.1.11 that is not compatible with it? And the most important question is, that what should I use instead of WAMP?

0

I changed the postLogin() and getLogin() functions to test what Auth::user() returns.

postLogin() function:

...
       if (Auth::attempt($params)) {
            $request->session()->put('current_user',Auth::user());
            return Auth::user();
            //return Redirect::route('dashboard');
       }
...

Then I can login successfully and see complete user information.

After that, changed getLogin() function as follows:

...
     return Auth::user();
...

If I access http://localhost/login, I see a blank page, which means Auth::user() returns null.

I guess Auth::user() is volatile. So after logging in Laravel deletes user data?

I expect someone can fix my problem.

0

I have solved my problem.

Learner: Check out your users table. I replaced the original ID column with UID and that was the problem. When I changed it back to id it instantly started working..

0

Hello, @incendiary01, does it mean that u rename the column from "ID" to "something" and then rename it again to "id" ?

0

I have the same problem please help me. I have 2 project with same database. One works good and seccond problem with Auth::user().

0

TwinLight said:

Hello, @incendiary01, does it mean that u rename the column from "ID" to "something" and then rename it again to "id" ?

This solution doesn't work for me. More ideas?

0

If I use auth::attempt() with my form data, it comes back null....... I know the data is correct and I know that the system is validating the user, but it's not creating Auth::user object....

0

I have the same problem and already solved. Solution : Make sure your primary key in users table is 'id' (Case Sensitive)

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Learner learner Joined 18 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.