chore: temp solution for fetching clerk on every navigated

This commit is contained in:
Aslam H
2024-10-07 17:01:26 +07:00
parent 950ebc3dad
commit b43c9762a1
5 changed files with 41 additions and 91 deletions
+11 -8
View File
@@ -4,12 +4,14 @@ import {
Outlet,
ScrollRestoration,
createRootRouteWithContext,
useLocation,
} from "@tanstack/react-router"
import { Body, Head, Html, Meta, Scripts } from "@tanstack/start"
import * as React from "react"
import { fetchClerkAuth } from "~/actions"
import { DefaultCatchBoundary } from "~/components/DefaultCatchBoundary.js"
import { NotFound } from "~/components/NotFound.js"
import { isServer } from "~/lib/utils"
import appCss from "~/styles/app.css?url"
export const TanStackRouterDevtools =
@@ -64,17 +66,18 @@ export const Route = createRootRouteWithContext<{
{ rel: "manifest", href: "/site.webmanifest", color: "#fffff" },
{ rel: "icon", href: "/favicon.ico" },
],
beforeLoad: async ({ cause }) => {
if (cause !== "stay") {
const { user } = await fetchClerkAuth()
return {
user,
}
}
beforeLoad: async ({ context, cause, location }) => {
// console.log(cause, location)
const { user } = await fetchClerkAuth()
return {
user: null,
user,
}
// }
// return {
// user: null,
// }
},
errorComponent: (props) => {
return (
+5 -7
View File
@@ -2,13 +2,11 @@ import { createFileRoute, Outlet, redirect } from "@tanstack/react-router"
export const Route = createFileRoute("/_layout/_pages/_protected")({
beforeLoad: ({ context, location, cause }) => {
if (cause !== "stay") {
if (!context?.user?.userId) {
throw redirect({
to: "/sign-in/$",
search: { redirect_url: location.pathname },
})
}
if (!context?.user?.userId) {
throw redirect({
to: "/sign-in/$",
search: { redirect_url: location.pathname },
})
}
},
component: () => <Outlet />,