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.tslogin.tsxprofile.tsxThe issue:
The issue is that.... when I click the
Logoutbutton on the Profile page it makes a request to my/auth/logoutroute.. and runsmutateUserto setisLoggedInto false.. it then redirects to my/loginroute and runs the useSWR/auth/profilerequest 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/profilebecause 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