So I was working with my Firebase project using just html and PHP, and sometimes when I logging in, it keeps telling me that my token was issued in the future. It happens again and again, I have no idea how to stop it.
Is there a way to make a new token? So that I finally can log in? Thank you.
Code :
login-process.php
if (isset($_POST['login_btn'])) {
$email = $_POST['email'];
$clearTextPassword = $_POST['pwd'];
try {
$user = $auth->getUserByEmail("$email");
try {
$signInResult = $auth->signInWithEmailAndPassword($email, $clearTextPassword);
$idTokenString = $signInResult->idToken();
try {
$verifiedIdToken = $auth->verifyIdToken($idTokenString);
$uid = $verifiedIdToken->claims()->get('sub');
$_SESSION['verified_user_id'] = $uid;
$_SESSION['idTokenString'] = $idTokenString;
$_SESSION['status'] = "Login Success.";
header('Location: home.php');
exit();
} catch (FailedToVerifyToken $e) {
$_SESSION['status_error'] = "The token is invalid: " . $e->getMessage();
header('Location: login.php');
exit();
}
} catch (Exception $e) {
$_SESSION['status_error'] = "Email atau kata sandi salah. Coba lagi.";
header('Location: login.php');
exit();
}
} catch (\Kreait\Firebase\Exception\Auth\UserNotFound $e) {
$_SESSION['status_error'] = $e->getMessage();
header('Location: login.php');
exit();
}
} else {
$_SESSION['status_error'] = "Not Allowed.";
header('Location: login.php');
exit();
}
auth.php (this file is included in every files that user needs to be logged in first)
if (isset($_SESSION['verified_user_id'])) {
$uid = $_SESSION['verified_user_id'];
$idTokenString = $_SESSION['idTokenString'];
try {
$verifiedIdToken = $auth->verifyIdToken($idTokenString);
} catch (FailedToVerifyToken $e) {
$_SESSION['expire_status'] = "Token Expired/Invalid. Please Login again.";
header('Location: logout.php');
exit();
}
} else {
$_SESSION['status_error'] = "Please Log in First.";
header('Location: login.php');
exit();
}