Detect User Login & Redirect

Technical Support
  • Hi everyone, thanks for any input on this.

    Is there a way to detect if a user is logged in to NodeBB and have them redirected depending on that status?

    User visits, a basic html home page.

    • If user has logged into NodeBB previously and is still logged in, redirect them to the Nodebb forum (
    • If the user is not logged in, do nothing.

    I would appreciate any guidance on this,
    Thanks for your time.

  • You can get loggedIn status from${username}

    It returns a json object with a loggedIn boolean.

    Example (using jquery to fetch)

    $.getJSON('', (data) => {
      if (data.loggedIn) window.location.href = ''
  • Thank you for your quick reply.

    Is there a way to check logged-in status without specifying a user?

    All I want to be able to do is to have a custom homepage for my NodeBB website that only displays to guests.

    If one of my registered (& logged in) users visits, have it send them to the forum rather than to the custom homepage.

    Thanks again for your help, appreciated.

  • Yup, you can fetch, it will return an error if not logged in, and an object if you are.

  • @yariplus to clarify, it's /api/me/, with the trailing slash. It is significant 🙂

Suggested Topics