49 lines
1.8 KiB
JavaScript
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 "/";
|
|
if (!to.startsWith("/") || to.startsWith("//")) return "/";
|
|
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.Y48nEW8J.js","_app/immutable/chunks/CS4xyx6M.js","_app/immutable/chunks/m2dceAnU.js","_app/immutable/chunks/DcegSV8N.js","_app/immutable/chunks/Bzak7iHL.js","_app/immutable/chunks/BMcrRaS1.js"];
|
|
const stylesheets = [];
|
|
const fonts = [];
|
|
|
|
export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
|
|
//# sourceMappingURL=5-B5o-1cPT.js.map
|