Refactor environment variable declarations and update asset references in SvelteKit project. Removed unused variables and updated client entry points and stylesheets for improved performance.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import PocketBase from "pocketbase";
|
||||
const POCKETBASE_URL = "https://pocketbase.ccllc.pro";
|
||||
const LOGIN_PATH = "/login";
|
||||
const LOGOUT_PATH = "/logout";
|
||||
function isPublicRoute(pathname) {
|
||||
return pathname === LOGIN_PATH || pathname.startsWith(LOGIN_PATH + "/") || pathname === LOGOUT_PATH;
|
||||
}
|
||||
const handle = async ({ event, resolve }) => {
|
||||
event.locals.pb = new PocketBase(POCKETBASE_URL);
|
||||
event.locals.pb.authStore.loadFromCookie(event.request.headers.get("cookie") || "");
|
||||
try {
|
||||
if (event.locals.pb.authStore.isValid) {
|
||||
await event.locals.pb.collection("users").authRefresh();
|
||||
}
|
||||
} catch {
|
||||
event.locals.pb.authStore.clear();
|
||||
}
|
||||
event.locals.user = event.locals.pb.authStore.record ?? null;
|
||||
if (!event.locals.user && !isPublicRoute(event.url.pathname)) {
|
||||
const redirectTo = event.url.pathname + event.url.search;
|
||||
const loginUrl = redirectTo && redirectTo !== "/" ? `${LOGIN_PATH}?redirectTo=${encodeURIComponent(redirectTo)}` : LOGIN_PATH;
|
||||
throw redirect(303, loginUrl);
|
||||
}
|
||||
const response = await resolve(event);
|
||||
response.headers.append(
|
||||
"set-cookie",
|
||||
event.locals.pb.authStore.exportToCookie({ httpOnly: false, sameSite: "Lax" })
|
||||
);
|
||||
return response;
|
||||
};
|
||||
export {
|
||||
handle
|
||||
};
|
||||
@@ -205,46 +205,6 @@ function Card_content($$renderer, $$props) {
|
||||
bind_props($$props, { ref });
|
||||
});
|
||||
}
|
||||
function Card_header($$renderer, $$props) {
|
||||
$$renderer.component(($$renderer2) => {
|
||||
let {
|
||||
ref = null,
|
||||
class: className,
|
||||
children,
|
||||
$$slots,
|
||||
$$events,
|
||||
...restProps
|
||||
} = $$props;
|
||||
$$renderer2.push(`<div${attributes({
|
||||
"data-slot": "card-header",
|
||||
class: clsx(cn("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6", className)),
|
||||
...restProps
|
||||
})}>`);
|
||||
children?.($$renderer2);
|
||||
$$renderer2.push(`<!----></div>`);
|
||||
bind_props($$props, { ref });
|
||||
});
|
||||
}
|
||||
function Card_title($$renderer, $$props) {
|
||||
$$renderer.component(($$renderer2) => {
|
||||
let {
|
||||
ref = null,
|
||||
class: className,
|
||||
children,
|
||||
$$slots,
|
||||
$$events,
|
||||
...restProps
|
||||
} = $$props;
|
||||
$$renderer2.push(`<div${attributes({
|
||||
"data-slot": "card-title",
|
||||
class: clsx(cn("leading-none font-semibold", className)),
|
||||
...restProps
|
||||
})}>`);
|
||||
children?.($$renderer2);
|
||||
$$renderer2.push(`<!----></div>`);
|
||||
bind_props($$props, { ref });
|
||||
});
|
||||
}
|
||||
function _page($$renderer, $$props) {
|
||||
$$renderer.component(($$renderer2) => {
|
||||
let { data } = $$props;
|
||||
@@ -271,19 +231,6 @@ function _page($$renderer, $$props) {
|
||||
$$renderer2.push(`<main class="container mx-auto flex flex-col gap-6 py-8"><div class="flex items-center justify-between"><h1 class="text-2xl font-semibold">Stackq Items</h1> <span class="text-muted-foreground text-sm">${escape_html(items.length)} items</span></div> `);
|
||||
Card($$renderer2, {
|
||||
children: ($$renderer3) => {
|
||||
Card_header($$renderer3, {
|
||||
children: ($$renderer4) => {
|
||||
Card_title($$renderer4, {
|
||||
children: ($$renderer5) => {
|
||||
$$renderer5.push(`<!---->Stackq_Items`);
|
||||
},
|
||||
$$slots: { default: true }
|
||||
});
|
||||
$$renderer4.push(`<!----> <p class="text-muted-foreground text-sm">PocketBase collection. Enable JS for create/edit/delete.</p>`);
|
||||
},
|
||||
$$slots: { default: true }
|
||||
});
|
||||
$$renderer3.push(`<!----> `);
|
||||
Card_content($$renderer3, {
|
||||
class: "p-0",
|
||||
children: ($$renderer4) => {
|
||||
@@ -656,7 +603,6 @@ function _page($$renderer, $$props) {
|
||||
},
|
||||
$$slots: { default: true }
|
||||
});
|
||||
$$renderer3.push(`<!---->`);
|
||||
},
|
||||
$$slots: { default: true }
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { fail, redirect } from "@sveltejs/kit";
|
||||
function safeRedirectTo(searchParams) {
|
||||
const to = searchParams.get("redirectTo");
|
||||
if (!to || typeof to !== "string") return "/";
|
||||
if (!to.startsWith("/") || to.startsWith("//")) return "/";
|
||||
if (!to || typeof to !== "string") return "/items";
|
||||
if (!to.startsWith("/") || to.startsWith("//")) return "/items";
|
||||
return to;
|
||||
}
|
||||
const load = ({ url, locals }) => {
|
||||
|
||||
Reference in New Issue
Block a user