Problems with backend auth when running a mutation immediately after login

Hi All,

I am having issues running a mutation the @requiresAuth immediately after a user logs in.

Once i get a successful response from the login I attempt to call my mutation and will get an error - ‘UNAUTHENTICATED’ error ‘You don’t have permission to do that.’ occurred in claimVideoMutation

I thought for some reason time may be the solution. So I did a setTimeout to run the mutation every second until it worked. It turns out after about 5 seconds the mutation worked.

I then recalled this ticket - When using dbAuth, don't call `getToken` multiple times per page by cannikin · Pull Request #5816 · redwoodjs/redwood · GitHub (which was an excellent change) but I wonder if this is causing my issue.

So, I attempted to getToken() and also tried reauthenticate() to see if i could get the backend up to date but that did not do the trick.

Does anyone have thoughts on where I may be going wrong?

The fact that it’s exactly 5 seconds sound it has something to do with that fix listed…that’s how long we “cache” the result for getToken() for. Sounds like the fact you’re logged out got cached, and now when you log in it’s still remembering the previous state. I’ve opened a ticket here and will investigate: [Bug]: When using dbAuth, a @requireAuth check on a mutation will fail if invoked immediately after login · Issue #6411 · redwoodjs/redwood · GitHub

1 Like