session verification
Unanswered
Pteromalid wasp posted this in #help-forum
Pteromalid waspOP
im handling session verification in middleware by calling a verifySession server action function. this will return an error (and delete the session cookie) or a data response. in the middleware im redirecting to index if the session is not valid, im protecting one route currently. my question is how do i handle client side notification to let the user know if the cookie is expired and deleted. also how do i handle updating the signedIn state change? im currently using a sessionManagement component that is wrapping children in the root layout but having issues with toast not showing from changing the url params and handling in the component. idk what the best way to do this is
1 Reply
how do i handle client side notification to let the user know if the cookie is expired and deleted.Usually this is a bit complex only if you want to really have real-time session management. Depending on your use case, you might not need this. Regardless of your use case, this can be done by using a react hook to poll the cookie check every few seconds. Then you can display popup or refresh whenever the cookies is deleted.
also how do i handle updating the signedIn state change?You can re-read the cookie. If your sign In returns successfully and/or cookies has been set, the new cookie should contain the new JWT that contains the new user information. Using these you can trigger an update for the client-side session management to update the whole app. Or you could just refresh and rely the server to provide the correct ocntent.