aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/invoice
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-29 14:40:25 -0700
committerAdam Soltys <[email protected]>2024-10-29 14:40:25 -0700
commita92dd4d39a86af41dd9cd6c9f58263a13f852906 (patch)
treed48137096599fcd15560724690124e0175d84c40 /src/routes/(app)/invoice
parent0cf898e843f23a915f0bf3787330336d9bb8c5d1 (diff)
downloadcoinos-ui-a92dd4d39a86af41dd9cd6c9f58263a13f852906.tar.gz
coinos-ui-a92dd4d39a86af41dd9cd6c9f58263a13f852906.zip
check for user before preloading
Diffstat (limited to 'src/routes/(app)/invoice')
-rw-r--r--src/routes/(app)/invoice/+page.server.ts40
-rw-r--r--src/routes/(app)/invoice/+server.ts6
2 files changed, 23 insertions, 23 deletions
diff --git a/src/routes/(app)/invoice/+page.server.ts b/src/routes/(app)/invoice/+page.server.ts
index 5f3c38d3..8d2f3b7f 100644
--- a/src/routes/(app)/invoice/+page.server.ts
+++ b/src/routes/(app)/invoice/+page.server.ts
@@ -1,29 +1,29 @@
+import type { Invoice } from "$lib/types";
import { auth, post } from "$lib/utils";
import { error, redirect } from "@sveltejs/kit";
-import type { Invoice } from "$lib/types";
-export let load = async ({ cookies, parent }) => {
- let aid = cookies.get("aid");
- let { subject, user, rates } = await parent();
- if (aid === user.id) redirect(307, `/${user.username}/receive`);
+export const load = async ({ cookies, parent }) => {
+ const aid = cookies.get("aid");
+ let { subject, user, rates } = await parent();
+ if (aid === user.id) redirect(307, `/${user.username}/receive`);
- let invoice: Invoice = {
- aid,
- rate: rates[user?.currency || subject?.currency],
- };
+ let invoice: Invoice = {
+ aid,
+ rate: rates[user?.currency || subject?.currency],
+ };
- if (!user) user = subject;
+ if (!user) user = subject;
- try {
- invoice = await post("/invoice", { invoice, aid, user }, auth(cookies));
- } catch (e) {
- console.log(e);
- error(500, "Failed to generate invoice");
- }
+ try {
+ invoice = await post("/invoice", { invoice, aid, user }, auth(cookies));
+ } catch (e) {
+ console.log(e);
+ error(500, "Failed to generate invoice");
+ }
- let { id } = invoice;
+ const { id } = invoice;
- if (invoice.memoPrompt && !invoice.memo) {
- redirect(307, `/invoice/${id}/memo`);
- } else redirect(307, `/invoice/${id}`);
+ if (invoice.memoPrompt && !invoice.memo) {
+ redirect(307, `/invoice/${id}/memo`);
+ } else redirect(307, `/invoice/${id}`);
};
diff --git a/src/routes/(app)/invoice/+server.ts b/src/routes/(app)/invoice/+server.ts
index 0b5eb04e..f20d70f3 100644
--- a/src/routes/(app)/invoice/+server.ts
+++ b/src/routes/(app)/invoice/+server.ts
@@ -1,7 +1,7 @@
import { auth, post } from "$lib/utils";
import { json } from "@sveltejs/kit";
-export const POST = async ({ cookies: c, request: r }) => {
- const j = await r.json();
- return json(await post("/invoice", j, auth(c)));
+export const POST = async ({ cookies, request }) => {
+ const body = await request.json();
+ return json(await post("/invoice", body, auth(cookies)));
};