When the page loads, a cookie is created via PHP prior to any other content or headers with this code:
$steam_login_verify = SteamSignIn::validate();
if(isset($_COOKIE['userid']))
{
//work with cookie value to get data;
$steam_login_verify = $_COOKIE['userid'];
$id = new SteamId($steam_login_verify);
$name = $id->getNickname();
$baseUrl = $id->getBaseUrl();
$medAvatar = $id->getMediumAvatarUrl();
} else if(!empty($steam_login_verify))
{
//create the cookie and store the user id as the value
$exDate = time()+60*60*24*365;
setcookie('userid', $steam_login_verify, $exDate,'/');
$id = new SteamId($steam_login_verify);
$name = $id->getNickname();
$baseUrl = $id->getBaseUrl();
$medAvatar = $id->getMediumAvatarUrl();
}
I am then using James Auldridge’s cookies plugin for jQuery to manage the cookie.
Once the user logs in via Stream, their Steam64Id is stored in the cookie for a year to keep them from having to log in every time they visit they page (assuming they will visit it on a regular basis).
I then use the Steam64Id in an ajax call to get all of the users friends and populate a select element with their names.
On the page is a “Logout” button that, when clicked, will delete the cookie and refresh the page, causing the user to have to login via Steam again. This is where I am having the issue.
As long as the ajax call is running (and it takes a while to run ~57 sec) the logout button works just fine. Once that call is complete and the select element is populated, the logout button fails with an error in the console:
Uncaught TypeError: Cannot call method 'del' of undefined
The code that this error refers to is the function that deletes the cookie and refreshes the page:
$('#logout').click(function() {
$.cookies.del('userid');
window.location.reload();
});
I do not understand the error, or why it is being thrown. Any help here would be great.
I would have to see more client side code and the AJAX response to be sure, but I suspect that the AJAX response includes a SCRIPT tag which reloads jQuery, causing all loaded plugins (
$.cookiesreference included) to be deleted.Remember that
$.cookiesis an alias tojaaulde.utils.cookiesso part of your troubleshooting could be to use that instead and see if it works then.