Custom auth flow is not saving the token

I’m following https://docs.retool.com/docs/custom-api-authentication doc for setup custom auth in my retool application. Everything is working fine, except step 5 " Saving the Authentication Token". I’m trying to set a variable name PASSWORD from my response JSON but it’s always showing undefined. I’ve tries multiple ways to access it but every time it reacts the same.

My login response structure:- https://prnt.sc/wfsabt
Using token in a header:- https://prnt.sc/wfsbpb
Define a variable:- https://prnt.sc/wfscv2
I also tried {{http1}}, {{http1.body}}, {{http1.body.json.name}} and etc… but everytime it return undefined in PASSWORD.
TIA

Hey @tacenda and welcome to the forum! Thanks for the detailed screenshots.

Have you tried {{ http1.body.data.token }}? (or .name, not sure which you’re trying to extract). We might have erred in the docs there by putting .json instead of .data.

Hi @justin, Thanks for your reply.
Yes, I have tried {{ http1.body.data.token }} and I also tried some combinations with http2 instead of http1 but every time it sets undefined in password. When I set a hardcoded value then it works fine.

1 Like

@tacenda very strange. It does seem like you’re following the docs pretty much word for word, I’m not sure what the issue is. Could you attach a screenshot of the whole custom auth flow that you’ve built so I can see all of the steps?

HI @justin, Here are screenshots of my setup:-

  1. Set URL & Header :- https://prnt.sc/whje1c
  2. Custom Auth Modal:- https://prnt.sc/whjgg6
  3. Custom API Request:- https://prnt.sc/whjhel
  4. Define a variable:- https://prnt.sc/whji9k

Also, Check the login response https://prnt.sc/wfsabt

I was tried to set a hardcoded value for PASSWORD under Define a variable and it put that value in header successfully but unable to set from login response. https://prnt.sc/whjkv4

@tacenda thanks!! I think the issue might be that you’re missing a step in the custom auth workflow - seems like you have two steps defined, and then a refresh step, where you’re defining your variable. Can you move the “define a variable” step to the workflow itself? It should be the third step, right after you make your POST request with the username and password.

2 Likes

Thanks @justin! It’s working.

1 Like

Woohoo awesome!!