mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-27 10:47:14 +02: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) => {
|
export const fetchClerkAuth = createServerFn("GET", async (_, ctx) => {
|
||||||
const auth = await getAuth(ctx.request)
|
const auth = await getAuth(ctx.request)
|
||||||
|
|
||||||
return {
|
return auth
|
||||||
user: auth,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getFeatureFlag = createServerFn(
|
export const getFeatureFlag = createServerFn(
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ import {
|
|||||||
Outlet,
|
Outlet,
|
||||||
ScrollRestoration,
|
ScrollRestoration,
|
||||||
createRootRouteWithContext,
|
createRootRouteWithContext,
|
||||||
useLocation,
|
|
||||||
} from "@tanstack/react-router"
|
} from "@tanstack/react-router"
|
||||||
import { Body, Head, Html, Meta, Scripts } from "@tanstack/start"
|
import { Body, Head, Html, Meta, Scripts } from "@tanstack/start"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { fetchClerkAuth } from "~/actions"
|
import { fetchClerkAuth } from "~/actions"
|
||||||
import { DefaultCatchBoundary } from "~/components/DefaultCatchBoundary.js"
|
import { DefaultCatchBoundary } from "~/components/DefaultCatchBoundary.js"
|
||||||
import { NotFound } from "~/components/NotFound.js"
|
import { NotFound } from "~/components/NotFound.js"
|
||||||
import { isServer } from "~/lib/utils"
|
|
||||||
import appCss from "~/styles/app.css?url"
|
import appCss from "~/styles/app.css?url"
|
||||||
|
|
||||||
export const TanStackRouterDevtools =
|
export const TanStackRouterDevtools =
|
||||||
@@ -66,18 +64,15 @@ export const Route = createRootRouteWithContext<{
|
|||||||
{ rel: "manifest", href: "/site.webmanifest", color: "#fffff" },
|
{ rel: "manifest", href: "/site.webmanifest", color: "#fffff" },
|
||||||
{ rel: "icon", href: "/favicon.ico" },
|
{ rel: "icon", href: "/favicon.ico" },
|
||||||
],
|
],
|
||||||
beforeLoad: async ({ context, cause, location }) => {
|
beforeLoad: async ({ cause }) => {
|
||||||
// console.log(cause, location)
|
if (cause !== "stay") {
|
||||||
|
const auth = await fetchClerkAuth()
|
||||||
const { user } = await fetchClerkAuth()
|
return { auth }
|
||||||
return {
|
|
||||||
user,
|
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// return {
|
return {
|
||||||
// user: null,
|
auth: null,
|
||||||
// }
|
}
|
||||||
},
|
},
|
||||||
errorComponent: (props) => {
|
errorComponent: (props) => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { createFileRoute, Outlet, redirect } from "@tanstack/react-router"
|
|||||||
|
|
||||||
export const Route = createFileRoute("/_layout/_pages/_protected")({
|
export const Route = createFileRoute("/_layout/_pages/_protected")({
|
||||||
beforeLoad: ({ context, location, cause }) => {
|
beforeLoad: ({ context, location, cause }) => {
|
||||||
if (!context?.user?.userId) {
|
if (cause === "stay") return
|
||||||
|
if (!context?.auth?.userId) {
|
||||||
throw redirect({
|
throw redirect({
|
||||||
to: "/sign-in/$",
|
to: "/sign-in/$",
|
||||||
search: { redirect_url: location.pathname },
|
search: { redirect_url: location.pathname },
|
||||||
|
|||||||
@@ -290,7 +290,6 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {
|
|||||||
onUpdate={(c) => updatePageContent(c, page)}
|
onUpdate={(c) => updatePageContent(c, page)}
|
||||||
handleKeyDown={handleContentKeyDown}
|
handleKeyDown={handleContentKeyDown}
|
||||||
onBlur={(c) => updatePageContent(c, page)}
|
onBlur={(c) => updatePageContent(c, page)}
|
||||||
onNewBlock={(c) => updatePageContent(c, page)}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user