Files
Stackq/build/server/chunks/5-DDffnZxb.js
T
2026-02-17 14:58:53 -06:00

49 lines
1.8 KiB
JavaScript

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.Cf_DU5yu.js","_app/immutable/chunks/DPCugUAM.js","_app/immutable/chunks/MIlO0V30.js","_app/immutable/chunks/D6Mj8HfB.js","_app/immutable/chunks/Bzak7iHL.js","_app/immutable/chunks/DBvDeCtH.js"];
const stylesheets = [];
const fonts = [];
export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
//# sourceMappingURL=5-DDffnZxb.js.map