HR token issue

This commit is contained in:
Gowtham M 2026-02-26 15:27:26 +05:30
parent 6f3032d20d
commit a3cb96ce74
3 changed files with 20 additions and 9 deletions

View File

@ -648,7 +648,8 @@ class RestAuthenticationController extends AdminController
'function' => $th->getTrace()[0]['function'] ?? null,
'class' => $th->getTrace()[0]['class'] ?? null,
];
return $this->respond(['status' => 'failed','code' => 500,'data' => $th, 'error_data' => $errorData],500);
log_message('error', 'Error Data: ' . json_encode($errorData));
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
}
}
@ -2345,7 +2346,7 @@ class RestAuthenticationController extends AdminController
}
$decoded = $result['decoded'];
$userId = $decoded['id'] ?? null;
$userId = $decoded['post_hr_id'] ?? null;
if (!$userId) {
return $this->respond([

View File

@ -115,9 +115,19 @@ class AuthJWT implements FilterInterface
}
// Refresh sliding expiration
$model->update($id, [
'token_time_out' => time() + getenv('TOKENTIMEOUT')
]);
$newExpiry = time() + getenv('TOKENTIMEOUT');
if (!isset($decoded['emp_code'])) {
// HR user: refresh token_time_out across all branches (same mobile/email)
// so switching branches doesn't cause an unexpected expiry
$field = !empty($user['mobile']) ? 'mobile' : 'email';
$model->where($field, $user[$field])
->where('contact_type', 'client')
->where('is_active', 1)
->update(null, ['token_time_out' => $newExpiry]);
} else {
$model->update($id, ['token_time_out' => $newExpiry]);
}
return true;
}

View File

@ -136,7 +136,7 @@ class JWTToken
$token = $jwtParts[0];
try {
$decoded = JWT::decode($token, new Key("secret", 'HS512'));
$decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512'));
return json_encode(['status' => true, 'message' => 'Token is valid', 'data' =>$decoded->data->id ]);
} catch (ExpiredException $e) {
return json_encode(['status' => false, 'message' => 'Token has expired']);
@ -158,7 +158,7 @@ class JWTToken
$jwtParts = explode(' ', $jwt);
$token = $jwtParts[1];
$decoded = JWT::decode($token, new Key("secret", 'HS512'));
$decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512'));
return $decoded->id;
}
@ -169,7 +169,7 @@ class JWTToken
$jwtParts = explode(' ', $jwt);
$token = $jwtParts[1];
$decoded = JWT::decode($token, new Key("secret", 'HS512'));
$decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512'));
return $decoded->role;
}
@ -181,7 +181,7 @@ class JWTToken
$jwtParts = explode(' ', $jwt);
$token = $jwtParts[1];
$decoded = JWT::decode($token, new Key("secret", 'HS512'));
$decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512'));
return $decoded;
}