ShopMessage can also let you know when it detects that a visitor is logged into Facebook. This can be useful if there are certain elements on the page that you only want to reveal to logged-in users.


Facebook SDK Limitation

Because ShopMessage uses the Facebook SDK, it will never invoke your callback if the visitor is logged out. The callback returns only in the affirmative.

_shopmsg('facebook.loginStatus', function onLoggedIn() {
  // visitor is logged in
let fbLoggedIn = new Promise((resolve, reject) => {
  let hasTimedOut = false;
  _shopmsg('facebook.loginStatus', () => {
    if (!hasTimedOut) {
  // I won't know if the visitor is actually logged out, so 
  // just wait a max of 3secs to find out or else bail
  setTimeout(() => {
    hasTimedOut = true;
  }, 3000);

fbLoggedIn.then(() => {
  // if the promise is resolved, then I know the visitor is logged in