diff --git a/nodejs.module b/nodejs.module
index b2305bd..38a7d63 100644
--- a/nodejs.module
+++ b/nodejs.module
@@ -513,6 +513,9 @@ function nodejs_auth_check($message) {
  * Default Node.js auth check callback implementation.
  */
 function nodejs_auth_check_callback($auth_token) {
+  if (\Drupal::currentUser()->isAnonymous()) {
+    return 0;
+  }
   return \Drupal::database()->query("SELECT uid FROM {sessions} WHERE MD5(sid) = :auth_key", array(':auth_key' => $auth_token))->fetchField();
 }
 
@@ -531,6 +534,11 @@ function nodejs_auth_get_token(SessionInterface $session) {
  * Default nodejs_auth_get_token() implementation.
  */
 function nodejs_auth_get_token_callback(SessionInterface $session) {
+  // Anonymous users all use the same token.
+  if (\Drupal::currentUser()->isAnonymous()) {
+    return 'anonymous_user';
+  }
+
   // The session id stored in the database is hashed. Use the same to generate
   // the token.
   return md5(Crypt::hashBase64($session->getId()));
