You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my Login form component I use the login function to update the global state, that is store the access token. This token should be used for all of the subsequent requests in the Authorization header.
How can I useSwr with an updated fetcher function (that has the token)?
exportconstLogin=()=>{const[auth,login]=useGlobalStore(state=>([state.auth,state.login]));consthandleSubmit=async(e: React.FormEvent)=>{e.preventDefault();try{constresponse=awaitexecuteLogin({data: payload});consttoken=response.data.token;// Update the global state with the tokenlogin(token);// TODO: start using an updated useSwr fetcher here}catch(e){alert('Bad username or password.');}};}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In my
Login
form component I use thelogin
function to update the global state, that is store the access token. This token should be used for all of the subsequent requests in theAuthorization
header.How can I
useSwr
with an updated fetcher function (that has the token)?Beta Was this translation helpful? Give feedback.
All reactions