mirror of
https://github.com/linsa-io/linsa.git
synced 2026-02-23 19:05:01 +01:00
fix: dont refetch every navigate
This commit is contained in:
@@ -21,9 +21,7 @@ const DEFAULT_VALUES = {
|
||||
export const fetchClerkAuth = createServerFn("GET", async (_, ctx) => {
|
||||
const auth = await getAuth(ctx.request)
|
||||
|
||||
return {
|
||||
user: auth,
|
||||
}
|
||||
return auth
|
||||
})
|
||||
|
||||
export const getFeatureFlag = createServerFn(
|
||||
|
||||
@@ -4,14 +4,12 @@ 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 =
|
||||
@@ -66,18 +64,15 @@ export const Route = createRootRouteWithContext<{
|
||||
{ rel: "manifest", href: "/site.webmanifest", color: "#fffff" },
|
||||
{ rel: "icon", href: "/favicon.ico" },
|
||||
],
|
||||
beforeLoad: async ({ context, cause, location }) => {
|
||||
// console.log(cause, location)
|
||||
|
||||
const { user } = await fetchClerkAuth()
|
||||
return {
|
||||
user,
|
||||
beforeLoad: async ({ cause }) => {
|
||||
if (cause !== "stay") {
|
||||
const auth = await fetchClerkAuth()
|
||||
return { auth }
|
||||
}
|
||||
// }
|
||||
|
||||
// return {
|
||||
// user: null,
|
||||
// }
|
||||
return {
|
||||
auth: null,
|
||||
}
|
||||
},
|
||||
errorComponent: (props) => {
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,8 @@ import { createFileRoute, Outlet, redirect } from "@tanstack/react-router"
|
||||
|
||||
export const Route = createFileRoute("/_layout/_pages/_protected")({
|
||||
beforeLoad: ({ context, location, cause }) => {
|
||||
if (!context?.user?.userId) {
|
||||
if (cause === "stay") return
|
||||
if (!context?.auth?.userId) {
|
||||
throw redirect({
|
||||
to: "/sign-in/$",
|
||||
search: { redirect_url: location.pathname },
|
||||
|
||||
@@ -290,7 +290,6 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {
|
||||
onUpdate={(c) => updatePageContent(c, page)}
|
||||
handleKeyDown={handleContentKeyDown}
|
||||
onBlur={(c) => updatePageContent(c, page)}
|
||||
onNewBlock={(c) => updatePageContent(c, page)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user