refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] Can't refetch Auth

Open stnguyen90 opened this issue 2 years ago • 1 comments

Describe the bug

My app has another way to authenticate the user outside of the authProvider's login method. After successfully logging in without the authProvider, I try to call refetch() from useAuthenticated() and then list('tasks'), but I get redirected to the login page despite the refetch() executing successfully.

Steps To Reproduce

  1. login w/o the authProvider
  2. call useAuthenticated().refetch()
  3. call `list('tasks')

Expected behavior

The user is taken to the List Tasks page, however they are taken to the login page.

Screenshot

No response

Desktop

No response

Mobile

No response

Additional Context

Link to discord thread: https://discord.com/channels/837692625737613362/1043053352486977577/1043053352486977577

stnguyen90 avatar Nov 18 '22 22:11 stnguyen90

Hey @stnguyen90,

authProvider's login, register and logout functions invalidates the auth stores for your application. When you authenticate outside of the authProvider, you must manually invalidate the auth store like this.

Because, the routerProvider calls the useAuthenticated with a different queryKey to prevent the loop in some cases. So you need to invalidate it for the routerProvider to know if you are auth.

Our suggestion for your case is to use the authProvider's register and the useRegister hook. We will discuss the issue with the team again, maybe we will make changes to the codebase, stay tuned 🙏🏻

salihozdemir avatar Nov 21 '22 12:11 salihozdemir