API Redirect Rules

  • jocenunes-1303930399919050772

    Joce Nunes

    5 months 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?
    1303930400204128316-
  • Tod-1303930402305605693

    Tod

    5 months ago

    Great energy @Joce Nunes! Your continuous contribution to the toddle Community just made you advance to Community Level 4!
  • andreasmoller-1303949550507261953

    Andreas Møller

    5 months ago

    The else part of the first node should be null or false
  • jocenunes-1303958717699588116

    Joce Nunes

    5 months ago

    Even so, it is redirecting, even though it is logged in.
  • andreasmoller-1303958876970029137

    Andreas Møller

    5 months ago

    Can you show me the formula?
  • jocenunes-1303959070859988993

    Joce Nunes

    5 months ago

    1303959070725636196-
  • jocenunes-1303959432027176980

    Joce Nunes

    5 months ago

    Here logged in.
    1303959431402487828-
    1303959431762939934-
  • andreasmoller-1303963817763409950

    Andreas Møller

    5 months ago

    What status code are you getting?
  • jocenunes-1303967553206620180

    Joce Nunes

    5 months ago

    302
  • I saying here.
    1303967755258822656-
  • andreasmoller-1303969347806433280

    Andreas Møller

    5 months ago

    I meant for the api request
  • jocenunes-1303969439460626464

    Joce Nunes

    5 months ago

    I create a new page and works. Let me check what is happening
  • andreasmoller-1303969508259659826

    Andreas Møller

    5 months ago

    Any chance that the code is not 200
  • jocenunes-1303970807365632011

    Joce Nunes

    5 months 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
  • jocenunes-1303972580436217887

    Joce Nunes

    5 months 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?
  • andreasmoller-1303972776557674549

    Andreas Møller

    5 months ago

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

    Joce Nunes

    5 months ago

    Let me try this
  • andreasmoller-1303973692308586516

    Andreas Møller

    5 months ago

  • jocenunes-1303980874387161098

    Joce Nunes

    5 months 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.
  • andreasmoller-1303982526368452651

    Andreas Møller

    5 months ago

    I am not sure I understand what you are asking?
  • andreasmoller-1303983979472486443

    Andreas Møller

    5 months 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
  • 1303983989002080296-
  • andreasmoller-1303984450731773982

    Andreas Møller

    5 months ago

    When you need to access the token you use the Get HTTP-Only Cookie formula
    1303984450417197056-
  • andreasmoller-1303984951565226004

    Andreas Møller

    5 months 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
  • 1303985009408868352-
  • jocenunes-1303987699761418252

    Joce Nunes

    5 months 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?
  • andreasmoller-1303988694562373686

    Andreas Møller

    5 months 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.
  • jocenunes-1303989869407637585

    Joce Nunes

    5 months 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.