Best way to handle authenticated routes with http-only cookie
I am currently trying to find a way to process a http-only session cookie with Tanstack Router.
The docs explain that you can use the beforeLoad-fn to redirect to the login route if necessary.
My routes are
/login
/app (here starts the auth-area)
/app/vouchers
/app/...
However, as an http-only cookie cannot be read on the client side, this option is difficult to implement. Therefore I have a
So far, I haven't come up with anything other than handling this prop in the app component with the help of useEffect
I would be very happy to receive feedback on how you would solve this.
Thx!
The docs explain that you can use the beforeLoad-fn to redirect to the login route if necessary.
My routes are
/login
/app (here starts the auth-area)
/app/vouchers
/app/...
However, as an http-only cookie cannot be read on the client side, this option is difficult to implement. Therefore I have a
zustand-store, which keeps the isLoggedIn-prop. In case of an 401 error the prop is set to false.So far, I haven't come up with anything other than handling this prop in the app component with the help of useEffect
I would be very happy to receive feedback on how you would solve this.
Thx!