• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Detect User Login & Redirect

Scheduled Pinned Locked Moved Technical Support
5 Posts 3 Posters 622 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • node38N Offline
    node38N Offline
    node38
    wrote on last edited by
    #1

    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?

    Specifically,
    User visits www.example.com, a basic html home page.

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

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

    1 Reply Last reply
    0
  • yariplusY Offline
    yariplusY Offline
    yariplus Community Rep
    wrote on last edited by
    #2

    You can get loggedIn status from
    https://www.example.com/forum/api/user/${username}

    It returns a json object with a loggedIn boolean.

    Example (using jquery to fetch)

    $.getJSON('https://community.nodebb.org/api/user/yariplus', (data) => {
      if (data.loggedIn) window.location.href = 'https://www.example.com/forum/'
    })
    
    1 Reply Last reply
    2
  • node38N Offline
    node38N Offline
    node38
    wrote on last edited by
    #3

    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.

    1 Reply Last reply
    0
  • yariplusY Offline
    yariplusY Offline
    yariplus Community Rep
    wrote on last edited by
    #4

    Yup, you can fetch https://www.example.com/forum/api/me, it will return an error if not logged in, and an object if you are.

    julianJ 1 Reply Last reply
    1
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    replied to yariplus on last edited by
    #5

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

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development