Router context #1122
lucifer-crybaby
started this conversation in
Ideas
Router context
#1122
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.
-
I'm using file based router with context I can pass context and use it in beforeLoad so far so good, but the problem arises when I try to redirect user.
When api call fails because user did not verified their email I dispatch state to store(in this case RTK) something like
isEmailVerified
, in my beforeLoad I navigate user to/verify-email
route ifisEmailVerified
isfalse
but the beforeLoad is already fired so I have to manually do that and I think that works but I don't wanna do that all over the place I wanna centralize my auth related logic in one place like beforeLoad, so I was wondering are there any function that runs every time context changes like onContextChange etc...Login logic
Api intercepter
Auth provider
Home route logic
So flow goes like this if user logs in successfully redirect to
home route
, in the home route some api call happens like get user info, get product info, etc... if this request fails with 'Your email address is not verified.' I dispatch'ssetIsVerifiedEmail(false)
, so according to home route's beforeLoad logic it should redirect to/verify-email
route but beforeLoad is already fired user is already in home route. I mean I can manually do that but something like onContextChange would be great, or am I missing equivalent methods? English is not my primary one so excuse moi :P TIABeta Was this translation helpful? Give feedback.
All reactions