# Detecting logged in status in a builder page

**URL:** <https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766>\
**Category:** Visual Editor Help\
**Tags:** custom-code\
**Created:** [October 20, 2022, 11:24am UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766 "2022-10-20T11:24:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_at\_the\_pools](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Richard\_at\_the\_pools](https://forum.builder.io/u/Richard_at_the_pools)\
**Post date:** [October 20, 2022, 11:24am UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766/1 "2022-10-20T11:24:43Z")

</div>

Hi

On the load of my builder page, I obtain the logged in status using the custom code below (entered in the data tab). This works fine. The player can then log in using a button in the header. The login process is via a right-hand slider and the player doesn’t leave the actual page.

As the player doesn’t leave the page then the custom code doesn’t run, and the logged in status of the page is out of sync.

Any suggestions how I handle this? I know this is a vague question, but I really don’t know how to add more detail!

```auto

function fetchGqlFsbToken() {
  const token = sessionStorage.getItem('gql_jwt');
  const bearer = 'Bearer ' + token;
  if (token !== undefined) {
      fetch('https://t ****.com/qa_graphql', {
        method: 'POST',
        body: JSON.stringify(FsbTokenQuery),
        headers: { 'Authorization': bearer,
                    'content-type': 'application/json' }
      })
        .then((response) => response.json())
        .then((data) => {
          if (data.data.customerV2 != null) {
            state.customerId = data.data.customerV2.customer.customerId;
            state.fsbToken = data.data.token.fsbToken;
            state.displayName = data.data.customerV2.customer.username;
          } else {
            console.log(data.errors[0].message);
          }
        })
        .catch((error) => { console.error('Error:', error); });
  }
}

async function getFsbToken() { await fetchGqlFsbToken(); }

const FsbTokenQuery = 
  { query: '{ token { fsbToken } customerV2 { customer { customerId username } } }' };

async function main () {

  if (Builder.isServer) {
    console.log("running on server side");
  }

  if (Builder.isBrowser) {
    var w = window.innerWidth;
    if (w <= 640) state.device = "mobile";
    else state.device = "desktop";

    state.isLoggedIn = !!sessionStorage.getItem('gql_jwt');
    console.log("isLoggedIn", state.isLoggedIn);
    if (state.isLoggedIn) {
        await getFsbToken();
    }
  }
}

export default main();

```

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [October 21, 2022, 10:59am UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766/2 "2022-10-21T10:59:18Z")

</div>

Hi @Richard_at_the_pools,

Could you please share your builder content link associated with this issue?

---

<div class="post-metadata">

**Author:** ![Richard\_at\_the\_pools](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Richard\_at\_the\_pools](https://forum.builder.io/u/Richard_at_the_pools)\
**Post date:** [October 23, 2022, 10:06am UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766/3 "2022-10-23T10:06:24Z")

</div>

I could, but it is behind a VPN so you won’t be able to see it.

Can you confirm when mail() runs? I assume it is only on page load. Are there other events that [builder.io](http://builder.io) supports automatically?

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [October 26, 2022, 2:17pm UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766/4 "2022-10-26T14:17:52Z")

</div>

Hi @Richard_at_the_pools,

The main runs after the page render static contents. Does it work in preview mode?

You can try declaring the code outside the main and see if that works.

---

<div class="post-metadata">

**Author:** ![Richard\_at\_the\_pools](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Richard\_at\_the\_pools](https://forum.builder.io/u/Richard_at_the_pools)\
**Post date:** [November 7, 2022, 12:53pm UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766/5 "2022-11-07T12:53:35Z")

</div>

Where would I declare the code outside of main? In the same place under data tab/custom code

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [November 7, 2022, 1:25pm UTC](https://forum.builder.io/t/detecting-logged-in-status-in-a-builder-page/2766/6 "2022-11-07T13:25:07Z")

</div>

Hi @Richard_at_the_pools,

Yes, that’s right. Outside the main under the data tab or you can even try using custom code block.
