T
TanStack5mo ago
foreign-sapphire

Using beforeLoad for authentication routes while keeping route layout

I have a simple authentication checker for a route, like so:
export const checkAuthentication = (opts: {user: ApplicationUser}) => {
...
if !(opts.user.isAuthenticated) {
throw notFound();
}
}
export const checkAuthentication = (opts: {user: ApplicationUser}) => {
...
if !(opts.user.isAuthenticated) {
throw notFound();
}
}
there are 2 ways to use this, either inside loader or beforeLoad. loader doesn't work for me since it caches data and user changes. i could specify loaderDeps, but i'd have to do that for every route, not to mention there are other queries in loader. this leaves beforeLoad. it works, but the resulting not found component isn't loaded with the root layout, or any layout. is this a bug? i would expect parent layouts to still work even with beforeLoad failing, is that not the case?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?