Is it possible to do a jwt authentication?

is it possible to do a jwt authentication? I want to be able to renew the token when it expires

on request failure I call this function, but not work :cry:

if(getUsersApi.data[0].error == 'token expired' || ts_Token.value == null){
   Promise.resolve(generateToken.trigger()).then(data => {
      ts_Token.setValue(data[0].token)
      getUsersApi.trigger()             
   })
}

Hi @leosantosx!

How is your resource authentication currently set up? How do you provision the tokens?

Hi @ben

/ POST https://example/authenticate
    body: 
    { 
        "username": "value",
        "password": "value",
    }

    response: 
    {
        "token": "value",
        "expiresIn": "value"
    }



    / GET https://example/list-users
    headers: 
    {
        "token": "value",
        "Content-Type": "application/json"
    }

    response: list all users or message: "token expired"

Template:

how do i revalidate the token? :disappointed_relieved:

I see! If you define these requests inside the resource setup page - Retool will handle the authentication + refresh requests. There is an example of how to set this up in the Custom API Authentication docs

@ben Do you have an example (template)?

I'm not succeeding

@leosantosx can you share how you currently have this set up?




Uploading: Captura de tela 2021-06-23 110202.jpg...

it looks like you are setting the authentication inside the base request. But you need to add your token request to the auth section of the resource: