I want to ask, I created a function to get jwt tokens and request a new token if the old token has expired, which will then be stored in the database. this function/app works when i run it on my local server, but when i try to host my app on my domain it saves nothing. I've set the .env file according to the database I have at the hosting provider, is there something I'm missing? i'm using ci 4.2.1 btw
Code:
function akses_restapi($method, $url, $data)
{
$client = \Config\Services::curlrequest();
$model = new ModelToken();
$idToken = "1";
$token = $model->getToken($idToken);
$tokenPart = explode(".", $token);
$payload = $tokenPart[1];
$decode = base64_decode($payload);
$json = json_decode($decode, true);
$exp = $json['exp'];
$waktuSekarang = time();
if ($exp <= $waktuSekarang) {
$url = "myendpoint";
$form_params = [
'email' => 'myadminemail',
'password' => 'mypassword'
];
$response = $client->request('post', $url, ['http_errors' => false, 'form_params' => $form_params]);
$result = json_decode($response->getBody(), true);
$token = $result['access_token'];
$dataToken = [
'id' => $idToken,
'token' => $token
];
$model->save($dataToken);
}
$headers = [
'Authorization' => 'Bearer ' . $token
];
$response = $client->request($method, $url, ['headers' => $headers, 'http_errors' => false, 'form_params' => $data]);
return $response->getBody();
}