PricingDocsAcademy
Bluesky ...
Fri, Dec 13, 9:38 AM

API Redirect Rules

  • /attachments/1303930399919050772/1303930400204128316/image.png

    Joce Nunes

    1 month ago

    I'm setting up a redirect rule so that if my API response status is not 200, it should redirect to the Home page. The API has both auto-fetching and server-side fetching enabled.

    The issue is that, even when the API returns a 200 status (meaning it shouldn't redirect), the rule is ignoring this condition and redirecting to Home constantly. I also tested using "is server," but the redirection still happens without respecting the established logic.

    Does anyone know if this could be a bug, or am I doing something wrong in the implementation?
  • Tod

    1 month ago

    Great energy @Joce Nunes! Your continuous contribution to the toddle Community just made you advance to Community Level 4!
  • Andreas Møller

    1 month ago

    The else part of the first node should be null or false
  • Joce Nunes

    1 month ago

    Even so, it is redirecting, even though it is logged in.
  • Andreas Møller

    1 month ago

    Can you show me the formula?
  • /attachments/1303930399919050772/1303959070725636196/image.png

    Joce Nunes

    1 month ago

  • /attachments/1303930399919050772/1303959431402487828/image.png

    Joce Nunes

    1 month ago

    Here logged in.
  • Andreas Møller

    1 month ago

    What status code are you getting?
  • Joce Nunes

    1 month ago

    302
  • I saying here.
  • Andreas Møller

    1 month ago

    I meant for the api request
  • Joce Nunes

    1 month ago

    I create a new page and works. Let me check what is happening
  • Andreas Møller

    1 month ago

    Any chance that the code is not 200
  • Joce Nunes

    1 month ago

    I recreated everything again, and now it's working with the same formula. I'm not sure what happened, but if it happens again, I'll let you know. Thank you for your time
  • Joce Nunes

    1 month ago

    @Andreas Møller Andreas, I believe I’ve identified the issue. To obtain the user’s authentication token, I’m retrieving the store_id from localStorage. However, for some reason, this information isn’t being fetched correctly, resulting in an "unauthenticated user" error.

    Could this limitation be related to server-side processing?
  • Andreas Møller

    1 month ago

    Yes localStorage is a browser feature
  • Could you store it in a cookie instead with the set session cookie action?
  • Joce Nunes

    1 month ago

    Let me try this
  • Andreas Møller

    1 month ago

  • Joce Nunes

    1 month ago

    is it possible to save in cookie store_id = 2 and then get this in API parameter? Even reading the documentation I couldn't. Sorry for the ignorance.
  • Andreas Møller

    1 month ago

    I am not sure I understand what you are asking?
  • Andreas Møller

    1 month ago

    to use the access_token cookie you first need to install the browser plugin (If you dont have it already).
    When you login you use the Set session cookie action to save your token
  • /attachments/1303930399919050772/1303984450417197056/CleanShot_2024-11-07_at_08.28.122x.png

    Andreas Møller

    1 month ago

    When you need to access the token you use the Get HTTP-Only Cookie formula
  • Andreas Møller

    1 month ago

    The most common way that APIs accept access tokens is using Bearer authentication, so that is the default in toddle. You just have to add the Authorization header and toddle will fill out the rest
  • Joce Nunes

    1 month ago

    I'm using the access token to check if the user is logged in, and my backend is Xano. So far, everything is working correctly.

    The issue is that, since this is a SaaS, a user can have an account in Store A or Store B. I save the store_id in local storage, and in all API requests, I pass the store_id to retrieve the necessary information. For the user, I also need to retrieve their data by providing the store_id to check if they are logged into Store X or Y.

    The problem is that, when using redirect rules, I'm unable to obtain the store_id.

    I'm not sure how to use cookies (or if it's even possible) to store the store_id and access it on the server side, or if there is another way to solve this issue. Otherwise, this functionality, which I find amazing, unfortunately won't work for me.

    Is there any way to work around this problem?
  • Andreas Møller

    1 month ago

    Not if you want to call the API during server render. But if that is not important you can turn SSR off for that request.
  • Joce Nunes

    1 month ago

    Of course, how silly of me. I got a bit confused with this update, but it’s just a matter of disabling SSR. Thank you!
  • now it worked perfectly

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.