Help forum

This Endpoint Requires Bearer token

  • mightBeMatt

    1 year ago

    I have a simple login page that currently works which redirects the user to another page. On that page I am trying to retrieve information about that user. My backend is Supabase.

    I set up an API call for the user to Supabase and I made the formula in the screenshot to pass the bearer token to the API. But in preview it keeps giving me error 401: This Endpoint Requires Bearer token. What am I doing wrong?
    1330940095854940260-image.png
  • Tod

    1 year ago

    Great energy @mightBeMatt! Your continuous contribution to the toddle Community just made you advance to Community Level 1!
  • Max

    1 year ago

    That part looks good. Can you share the setup of your api call and also the login flow on your login page?
  • mightBeMatt

    1 year ago

    1330975089747038290-image.png
    1330975090069733417-image.png
    1330975090292166716-image.png
  • Max

    1 year ago

    You should set the session cookies "on success" of the sign in call. Right now, the session cookies are set before you get the answer
  • Also, when do you do the redirect?
  • mightBeMatt

    1 year ago

    the redirect is on the call: sign in success
  • mightBeMatt

    1 year ago

    I guess after typing this out it I see that it is redirecting before it has a chance to set the cookie
  • Lucas G

    1 year ago

    It is a common one.
    It should be Sign in -> on success Set Cookies -> on success Redirect
    💪1
  • mightBeMatt

    1 year ago

    Hmmm so i changed it now but I still get the same error. Moved the set session cookies to inside the api onSuccess
    1330984495226032274-image.png
  • mightBeMatt

    1 year ago

    maybe it is how I am setting the access token? I've tried a few different ways
    1330985345814102056-image.png
  • Max

    1 year ago

    You have nothing bound to the access token. It will always be empty
  • mightBeMatt

    1 year ago

    sorry for the confusion. In that screenshot i had temporarily deleted it.
  • mightBeMatt

    1 year ago

    the formula above is what I am currently using. Getting 401 error
  • Max

    1 year ago

    1. When do you redirect after calling the sign up endpoint?
    2. You can add a log node on success to see what the return data structure looks like
  • mightBeMatt

    1 year ago

    1330993034124329020-image.png
  • Tod

    1 year ago

    Great energy @mightBeMatt! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • Max

    1 year ago

    The "go to URL" needs to go in the "Success" Branch of the "Set Session cookie" action.
  • Right now, you navigate away before you received the answer from the api and set the cookie
  • mightBeMatt

    1 year ago

    good point. Yeah i guess there isn't a good reason to have it outside. But it still redirects inside the success branch and gives me an error
  • Max

    1 year ago

    Can you share your project URL? Then I can take a look
  • mightBeMatt

    1 year ago

    well now it seems to be working! I'm not sure if I could tell you why since it doesn't seem like I really changed any of the logic
  • Lucas G

    1 year ago

    Is it on success of the set session?
  • As noted earlier, it should be Sign in -> on success Set Cookies -> on success Redirect
  • Lucas G

    1 year ago

    Otherwise, it won't work consistently
  • mightBeMatt

    1 year ago

    Yes that is how i have it set
  • mightBeMatt

    1 year ago

    Ah I see what you are saying. If it doesn't set cookies successfully then it shouldn't redirect. Thank you all for your patience and assistance!
    💪1
  • Lucas G

    1 year ago

    Yeah, perhaps my comment wasn't clear enough.
    I meant it should be Sign in and on success of the sign in API call, Set Session Cookies and on success setting the access_token, then Go to URL/Redirect
    👍1