The userdata array to store in `session('userdata')`. */ public static function build(array $user, bool $isExternalAuth = false, bool $twoFAVerified = false): array { return [ 'id' => (int) $user['id'], 'name' => NameSanitizer::clean($user['firstname'] ?? ''), 'profileId' => $user['profileId'] ?? '', 'mail' => filter_var($user['username'] ?? '', FILTER_SANITIZE_EMAIL), 'clientId' => $user['clientId'] ?? '', // ALWAYS the role-NAME string the permission engine validates against — never the raw // DB int. This is the field whose drift caused the Bearer -32001 regression. 'role' => Roles::getRoleString($user['role']), 'settings' => ! empty($user['settings']) ? safe_unserialize($user['settings'], []) : [], 'twoFAEnabled' => $user['twoFAEnabled'] ?? false, 'twoFAVerified' => $twoFAVerified, 'twoFASecret' => $user['twoFASecret'] ?? '', 'isExternalAuth' => $isExternalAuth, 'createdOn' => ! empty($user['createdOn']) ? dtHelper()->parseDbDateTime($user['createdOn']) : dtHelper()->userNow(), 'modified' => ! empty($user['modified']) ? dtHelper()->parseDbDateTime($user['modified']) : dtHelper()->userNow(), ]; } }