I already looking for related issue with this but didn't solved yet.
- Auth::attempt() is success
- try to register session after Auth::attempt() is success
- remember_token field on users table is always null
This is my code:
AuthController:
protected function login(Request $request){
$result = [];
$rules = ['email' => 'required|email', 'password' => 'required|alphaNum|min:3'];
$validator = Validator::make($request->all(), $rules);
if($validator->fails()) {
$result['message'] = 'Login Failed';
}else{
$userdata = ['email' => $request->email, 'password' => $request->password];
if (Auth::attempt($userdata, $request->has('auth_remember'))) {
// dd(Auth::user()); << THIS DATA IS EXIST
// $request->session()->push('user.id', Auth::user()->id);
// $request->session()->push('user.name', Auth::user()->name);
// $request->session()->push('user.email', Auth::user()->email);
// dd($request->session()->all()); << THIS DATA IS EXIST
$result['message'] = 'Login successfull. Redirecting ...';
}else{
$result['message'] = 'User not found';
}
}
echo json_encode($result);
}
I have a middleware Auth when I go to http://.../dashboard, but...
- Auth::check() return false
- $request->session()->has('user') return false
Auth Middleware:
public function handle($request, Closure $next){
if($this->auth->viaRemember()) return $next($request);
if($this->auth->guest()){
if($request->ajax()){
return response('Unauthorized.', 401);
}else{
return redirect()->guest('login');
}
}
return $next($request);
}
- storage/framework/session already set to 777
- file session are generated
- app timezone already match with server settings and database settings
Any help would be appreciated.
user
table and its fields -id
,username
,password
are could be the problem. I tried to modifySessionGuard::user()
function, but it seems session is empty. Session has name, but there is no such file under /storage/framework/sessions. Is there no one to solve this problem? – Mironuser
table and its fields -id
,username
,password
was the problem. Try to change$primaryKey
and$table
ofUser
model according to your DB. – Miron