chore: fix formatting and add auth guards to dashboard route
This commit is contained in:
29
src/index.ts
29
src/index.ts
@@ -21,7 +21,10 @@ if (!isProduction) {
|
|||||||
app.get("**/manifest.json", servePwaAsset("src/manifest.json"));
|
app.get("**/manifest.json", servePwaAsset("src/manifest.json"));
|
||||||
app.get("/sw.js", servePwaAsset("src/sw.js"));
|
app.get("/sw.js", servePwaAsset("src/sw.js"));
|
||||||
app.get("**/sw.js", servePwaAsset("src/sw.js"));
|
app.get("**/sw.js", servePwaAsset("src/sw.js"));
|
||||||
app.get("/.well-known/assetlinks.json", servePwaAsset("src/.well-known/assetlinks.json"));
|
app.get(
|
||||||
|
"/.well-known/assetlinks.json",
|
||||||
|
servePwaAsset("src/.well-known/assetlinks.json"),
|
||||||
|
);
|
||||||
|
|
||||||
app.post("/__open-in-editor", ({ body }) => {
|
app.post("/__open-in-editor", ({ body }) => {
|
||||||
const { relativePath, lineNumber, columnNumber } = body as {
|
const { relativePath, lineNumber, columnNumber } = body as {
|
||||||
@@ -161,17 +164,29 @@ if (!isProduction) {
|
|||||||
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
|
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
|
||||||
if (pathname.includes(".") && !pathname.endsWith("/")) {
|
if (pathname.includes(".") && !pathname.endsWith("/")) {
|
||||||
const filename = path.basename(pathname);
|
const filename = path.basename(pathname);
|
||||||
|
|
||||||
// Try root of dist
|
// Try root of dist
|
||||||
const fallbackDistPath = path.join("dist", filename);
|
const fallbackDistPath = path.join("dist", filename);
|
||||||
if (fs.existsSync(fallbackDistPath) && fs.statSync(fallbackDistPath).isFile()) {
|
if (
|
||||||
|
fs.existsSync(fallbackDistPath) &&
|
||||||
|
fs.statSync(fallbackDistPath).isFile()
|
||||||
|
) {
|
||||||
filePath = fallbackDistPath;
|
filePath = fallbackDistPath;
|
||||||
}
|
}
|
||||||
// Special handling for PWA files in src
|
// Special handling for PWA files in src
|
||||||
else if (filename === "manifest.json" || filename === "sw.js" || pathname.includes("assetlinks.json")) {
|
else if (
|
||||||
const srcFilename = pathname.includes("assetlinks.json") ? ".well-known/assetlinks.json" : filename;
|
filename === "manifest.json" ||
|
||||||
|
filename === "sw.js" ||
|
||||||
|
pathname.includes("assetlinks.json")
|
||||||
|
) {
|
||||||
|
const srcFilename = pathname.includes("assetlinks.json")
|
||||||
|
? ".well-known/assetlinks.json"
|
||||||
|
: filename;
|
||||||
const fallbackSrcPath = path.join("src", srcFilename);
|
const fallbackSrcPath = path.join("src", srcFilename);
|
||||||
if (fs.existsSync(fallbackSrcPath) && fs.statSync(fallbackSrcPath).isFile()) {
|
if (
|
||||||
|
fs.existsSync(fallbackSrcPath) &&
|
||||||
|
fs.statSync(fallbackSrcPath).isFile()
|
||||||
|
) {
|
||||||
filePath = fallbackSrcPath;
|
filePath = fallbackSrcPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,17 @@ import {
|
|||||||
} from "@tanstack/react-router";
|
} from "@tanstack/react-router";
|
||||||
import { useSnapshot } from "valtio";
|
import { useSnapshot } from "valtio";
|
||||||
import { ColorSchemeToggle } from "@/components/ColorSchemeToggle";
|
import { ColorSchemeToggle } from "@/components/ColorSchemeToggle";
|
||||||
|
import { protectedRouteMiddleware } from "@/middleware/authMiddleware";
|
||||||
import { authClient } from "@/utils/auth-client";
|
import { authClient } from "@/utils/auth-client";
|
||||||
import { authStore } from "../../store/auth";
|
import { authStore } from "../../store/auth";
|
||||||
|
|
||||||
export const Route = createFileRoute("/dashboard")({
|
export const Route = createFileRoute("/dashboard")({
|
||||||
component: DashboardLayout,
|
component: DashboardLayout,
|
||||||
|
beforeLoad: protectedRouteMiddleware,
|
||||||
|
onEnter({ context }) {
|
||||||
|
authStore.user = context?.user as any;
|
||||||
|
authStore.session = context?.session as any;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function DashboardLayout() {
|
function DashboardLayout() {
|
||||||
|
|||||||
Reference in New Issue
Block a user