How do I prevent SWR from making requests? (Auth) #672
Unanswered
dihmeetree
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Ok.. probably a confusing topic but here goes. I have a simple app going with the following routes:
/profile -> Redirects to /login if SWR request to get user returns error
/login -> Redirects to /profile if SWR request to get user is successful and returns data
/signup -> Redirects to /profile if SWR request to get user is successful and returns data
useUser.ts
login.tsx
profile.tsx
The issue:
The issue is that.... when I click the
Logout
button on the Profile page it makes a request to my/auth/logout
route.. and runsmutateUser
to setisLoggedIn
to false.. it then redirects to my/login
route and runs the useSWR/auth/profile
request again -_-Is there a way to persist mutate data between pages in Next.js? So if i'm on the profile and run
mutateUser({ isLoggedIn: false })
and then redirect to my login page.. it won't try and run the useSWR request again?tldr:
Go to profile page -> Click logout button -> Redirect to login page (but don't re-run useSWR request
/auth/profile
because I already know user has logged out - so show login form)Any help would be appreciated :)
Beta Was this translation helpful? Give feedback.
All reactions