-
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Hi 👋
Summary
When using Leaf\Auth with a custom primary key (like p_id), the login fails because the internal DB helper uses a hardcoded ORDER BY id ASC inside first() causes:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'order clause'
Configuration
auth()->config([
'db.table' => 'pengguna',
'id.key' => 'p_id',
'password.key' => 'p_password'
]);
Login code
$data = request()->postData();
$success = auth()->login([
'p_username' => $data['username'],
'p_password' => $data['password']
]);
Where it breaks
Inside Auth::login():
$user = $this->db->select($table)->where($credentials)->first();
This calls Db::first():
public function first()
{
$this->query .= ' ORDER BY id ASC LIMIT 1'; // <- hardcoded "id"
return $this->fetchAssoc();
}
Expected Behavior
first() should use the configured primary key:
- From Auth config (
id.key) - Or simply use
->orderBy(Config::get('id.key'), 'asc')->limit(1)->fetchAssoc();
This should also apply to every other first() call inside Leaf\Auth
Environment
- LeafPHP version: 4.0
- Leaf\Db version: 4.0
- Leaf\Auth version: 4.2
- PHP version: 8.2
- Database: MySQL
Thank you.
Metadata
Metadata
Assignees
Labels
No labels