by TheAceOfHearts · 8y ago · 0 comments
If your application requires authentication, you should just use server-side rendering / routing for ungated views. If those views need to be interactive or whatnot, treat em as small separate frontend apps. Removing as many session management concerns out of the client-side SPA is always nice. You can pretty much get it down to only checking for 401 responses and a cross-tab session tracking mechanism (easily done with localStorage) to prevent impossible states from the user switching sessions.
Obviously client side routes will never be secure but that is not the point. The example code shows a way to protect your user from accessing routes/components that would not function properly without an authenticated user (Universal User Id and or unique email address).