I have to build a new system with a kind of old-style pre-existing MySQL database tables with Laravel 8 with Breeze. Already have a user data table that is totally different from the basic Auth system in Laravel 8. I am trying to figure out to make Auth system but it doesn't work right.
This is my User
model class.
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
protected $table = 'tb_user_info';
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
//'passwd',
'remember_token',
];
public function setPasswordAttribute($password)
{
$this->attributes['passwd'] = \DB::raw("password('$password')");
}
public function getAuthPassword()
{
return $this->passwd;
}
}
And this is my store
method in AuthenticatedSessionController
, which I figured it is using in login.
public function store(LoginRequest $request)
{
$credentials = $request->validate([
'mem_id' => ['required', 'email'],
'passwd' => ['required'],
]);
$user = User::select('mem_id', 'passwd')->where('mem_id', $request->mem_id)->first();
if ($user->mem_id == $request->mem_id && $user->passwd == $this->sql_password($request->passwd)) {
$request->session()->regenerate();
return redirect('/dashboard');
}
return back()->withErrors([
'mem_id' => 'The provided credentials do not match our records.',
]);
}
I thought it simply works, but after I try to login, it doesn't work at all, just keep redirecting back to the login page. I looked up the Network
tab in Chrome, it seems like the dashboard
page was called but it shows 302 Found
and called the login
page again.
Which part should I lookup for this situation? I am working on this for 3 days, nothing came up for a good solution. Please, please help me, I would be appreciated just a few tips.
Ps. Please don't answer like stop using the MySQL password for password
or why don't you make a new database table?
because it's meaningless answers. I would do that already if I can. This is a very limited situation at work. Please understand.