PricingBlog

Managing authentication

  • .paul.i-1108292056427806813

    Paul.I

    2 years ago

    Hello there !
    I have watched the video about authentication.
    Now I can login with Xano, and add the token on cookies
    But I have several pages that should be accessible only for authenticated user.
    How do you manage this part ?
    You do a call to auth/me on load of each page ?
    Is there a way to redirect directly users without token on cookies to homepage ?
    1
    👀1
    👍2
  • .paul.i-1110120919743074334

    Paul.I

    2 years ago

    No one for helping me ?
  • svenning-1110123456437162098

    svenning

    2 years ago

    We will get to you 😃👍
  • .paul.i-1110161802362359868

    Paul.I

    2 years ago

    Thanks a lot !
  • svenning-1110162867493277766

    svenning

    2 years ago

    I think I'm doing a auth/me on each page in my Xano projects — but @Andreas Møller might have a better solution 🤷‍♀️
  • andreasmoller-1110163960633765902

    Andreas Møller

    2 years ago

    Hi Paul
    The simplest way is to add a workflow to the Failed event of an API. If the request failed because the user is unauthenticated then you can redirect to the login page.
    1110163960507932714-CleanShot_2023-05-22_at_13.14.202x.png
  • .paul.i-1110175989918613514

    Paul.I

    2 years ago

    And then you launch this API in the event lifecycle "on load" ? Or just any API that requires auth in the page ?
  • andreasmoller-1110176710328074250

    Andreas Møller

    2 years ago

    Apis with Auto fetch enabled are automatically called when the page loads, or their input changes. So you dont need to do that.
    1110176710126751804-CleanShot_2023-05-22_at_14.04.272x.png
  • .paul.i-1110179014485749871

    Paul.I

    2 years ago

    Oh perfect missed the auto fetch, thanks a lot !
  • andreasmoller-1110179438924140625

    Andreas Møller

    2 years ago

    Yeah it is a bit subtle 🙂
  • .paul.i-1110179526220193932

    Paul.I

    2 years ago

    No pbm, as the support is great 😉
  • andreasmoller-1110179772509720659

    Andreas Møller

    2 years ago

    🙂
  • datomnz-1122053433009111042

    Tom Wrench

    2 years ago

    Hi Andreas, I tried this method for my project but the page that's supposed to be authenticated still shows for half a second for unauthenticated users before being redirected. Is there a way to redirect before the page actually loads, so the unauthenticated user doesn't see any of the authenticated page?
  • andreasmoller-1122053914792034430

    Andreas Møller

    2 years ago

    No not at the moment. But it is something we are looking into addressing
    👍1
  • swseagull-1233090988629819597

    SWSeagull

    1 year ago

    Has this been addressed yet?
  • andreasmoller-1233091317194559559

    Andreas Møller

    1 year ago

    No unfortunately not yet. But it is on the roadmap for this year
  • swseagull-1233307740604989520

    SWSeagull

    1 year ago

    Ok great, I have tried many different platforms and authentication is always the challenge. Handling this neatly is the biggest challenge when building applications rather than web pages.
  • andreasmoller-1233315459781103646

    Andreas Møller

    1 year ago

    Yes especially when working with different backends. I think there are still lots of ways we can improve it though 🙂