Refactor environment variable declarations, update client entry points, and optimize asset handling in SvelteKit project for improved performance and maintainability.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { f as fail, r as redirect } from './index-B2LGyy1l.js';
|
||||
|
||||
function safeRedirectTo(searchParams) {
|
||||
const to = searchParams.get("redirectTo");
|
||||
if (!to || typeof to !== "string") return "/items";
|
||||
if (!to.startsWith("/") || to.startsWith("//")) return "/items";
|
||||
return to;
|
||||
}
|
||||
const load = ({ url, locals }) => {
|
||||
if (locals.user) {
|
||||
throw redirect(303, safeRedirectTo(url.searchParams));
|
||||
}
|
||||
};
|
||||
const actions = {
|
||||
login: async ({ request, locals, url }) => {
|
||||
const data = await request.formData();
|
||||
const email = data.get("email")?.trim() ?? "";
|
||||
const password = data.get("password") ?? "";
|
||||
if (!email || !password) {
|
||||
return fail(400, { error: "Email and password are required.", email });
|
||||
}
|
||||
try {
|
||||
await locals.pb.collection("users").authWithPassword(email, password);
|
||||
} catch (err) {
|
||||
const message = err && typeof err === "object" && "message" in err ? String(err.message) : "Invalid email or password.";
|
||||
return fail(401, { error: message, email });
|
||||
}
|
||||
const redirectTo = safeRedirectTo(url.searchParams);
|
||||
throw redirect(303, redirectTo);
|
||||
}
|
||||
};
|
||||
|
||||
var _page_server_ts = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
actions: actions,
|
||||
load: load
|
||||
});
|
||||
|
||||
const index = 5;
|
||||
let component_cache;
|
||||
const component = async () => component_cache ??= (await import('./_page.svelte-3rk2vnq3.js')).default;
|
||||
const server_id = "src/routes/login/+page.server.ts";
|
||||
const imports = ["_app/immutable/nodes/5.u4tkKrg-.js","_app/immutable/chunks/CRDN6Mh7.js","_app/immutable/chunks/Dexp9pM5.js","_app/immutable/chunks/Bzak7iHL.js","_app/immutable/chunks/DcVg5zjO.js","_app/immutable/chunks/25AjRaeI.js"];
|
||||
const stylesheets = [];
|
||||
const fonts = [];
|
||||
|
||||
export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
|
||||
//# sourceMappingURL=5-BEJSjzl2.js.map
|
||||
Reference in New Issue
Block a user