aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-08-16 16:26:05 -0700
committerAdam Soltys <[email protected]>2022-08-16 16:26:05 -0700
commit7b9bc9be24a565d513c8904237563479265aee9f (patch)
tree4749a3d4dd845e13f23c38924752007a281775c0
parent4228d55f0be8497b2f8360460d68e99f14cc7d07 (diff)
downloadcoinos-ui-7b9bc9be24a565d513c8904237563479265aee9f.tar.gz
coinos-ui-7b9bc9be24a565d513c8904237563479265aee9f.zip
endpoint migrations
-rw-r--r--src/routes/+error.svelte24
-rw-r--r--src/routes/[username]/+page.svelte5
-rw-r--r--src/routes/invoice/[id]/+page.svelte5
-rw-r--r--src/routes/login/+page.server.js24
-rw-r--r--src/routes/logout/+page.server.js32
-rw-r--r--src/routes/register/+page.server.js11
-rw-r--r--src/routes/withdraw/+server.js8
7 files changed, 37 insertions, 72 deletions
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
index 78e7b5a6..e555a032 100644
--- a/src/routes/+error.svelte
+++ b/src/routes/+error.svelte
@@ -1,27 +1,9 @@
-<script context="module">
- throw new Error("@migration task: Replace error load function (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3293209)");
-
- // export function load({ error, status }) {
- // if (error.message.includes('not found')) {
- // error.message = 'Page not found.';
- // status = 404;
- // }
-
- // return {
- // props: {
- // error,
- // status
- // }
- // };
- // }
-</script>
-
<script>
+ import { page } from '$app/stores';
import { Icon, PageNotFound } from '$comp';
- export let status, error;
</script>
-{#if status === 404}
+{#if $page.error.message.includes('not found') || $page.status === 404}
<PageNotFound />
{:else}
<div class="flex justify-center items-center mt-20">
@@ -33,7 +15,7 @@
<Icon icon="error" style="mx-auto w-56" />
<h1 class="font-bold text-5xl">Error</h1>
- <p class="px-1 w-full md:w-96 break-all font-bold">{error.message.toUpperCase()}</p>
+ <p class="px-1 w-full md:w-96 break-all font-bold">{$page.error.message.toUpperCase()}</p>
<p>Please try again or contact support.</p>
</div>
</div>
diff --git a/src/routes/[username]/+page.svelte b/src/routes/[username]/+page.svelte
index c0183883..973e8798 100644
--- a/src/routes/[username]/+page.svelte
+++ b/src/routes/[username]/+page.svelte
@@ -1,12 +1,11 @@
<script>
- throw new Error("@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)");
-
import { browser } from '$app/env';
import { onMount } from 'svelte';
import { AppHeader, Icon, PageNotFound } from '$comp';
import { user } from '$lib/store';
import { copy } from '$lib/utils';
- export let username;
+ export let data;
+ $: ({ username } = data);
let lightningAddress = `${username}@coinos.io`;
diff --git a/src/routes/invoice/[id]/+page.svelte b/src/routes/invoice/[id]/+page.svelte
index 0252a6b1..d9f7543d 100644
--- a/src/routes/invoice/[id]/+page.svelte
+++ b/src/routes/invoice/[id]/+page.svelte
@@ -1,6 +1,4 @@
<script>
- throw new Error("@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)");
-
import { get, post, reverseFormat } from '$lib/utils';
import { browser } from '$app/env';
import { invoices, user, preferredCurrency } from '$lib/store';
@@ -9,7 +7,8 @@
import { onMount } from 'svelte';
import { copy } from '$lib/utils';
- export let amount, id, rate, status, text, username;
+ export let data;
+ $: ({ amount, id, rate, status, text, username } = data);
$invoices[id] = { amount, id, rate, status, text, username };
diff --git a/src/routes/login/+page.server.js b/src/routes/login/+page.server.js
index 7b70d944..2dfb962d 100644
--- a/src/routes/login/+page.server.js
+++ b/src/routes/login/+page.server.js
@@ -3,23 +3,19 @@ import cookie from 'cookie';
let maxAge = 30 * 24 * 60 * 60;
-export async function POST({ request }) {
+export async function POST({ setHeaders, request }) {
let body = await post('/login', await request.json());
let expires = new Date();
expires.setSeconds(expires.getSeconds() + maxAge);
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
- return {
- body,
- headers: {
- 'set-cookie': cookie.serialize('token', body.token, {
- httpOnly: true,
- maxAge,
- sameSite: 'lax',
- path: '/',
- expires
- })
- }
- };
+ setHeaders({
+ 'set-cookie': cookie.serialize('token', body.token, {
+ httpOnly: true,
+ maxAge,
+ sameSite: 'lax',
+ path: '/',
+ expires
+ })
+ });
}
diff --git a/src/routes/logout/+page.server.js b/src/routes/logout/+page.server.js
index 2b252aae..40ddcfff 100644
--- a/src/routes/logout/+page.server.js
+++ b/src/routes/logout/+page.server.js
@@ -1,3 +1,4 @@
+import { redirect } from '@sveltejs/kit';
import cookie from 'cookie';
const opts = {
@@ -7,21 +8,18 @@ const opts = {
};
export async function load({ request: { headers } }) {
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
- return {
- status: 302,
- headers: {
- location: '/logout/done',
- 'set-cookie': [
- cookie.serialize('token', '', {
- ...opts,
- expires: new Date(0)
- }),
- cookie.serialize('refresh_token', '', {
- ...opts,
- expires: new Date(0)
- })
- ]
- }
- };
+ setHeaders({
+ 'set-cookie': [
+ cookie.serialize('token', '', {
+ ...opts,
+ expires: new Date(0)
+ }),
+ cookie.serialize('refresh_token', '', {
+ ...opts,
+ expires: new Date(0)
+ })
+ ]
+ });
+
+ throw redirect(302, '/logout/done');
}
diff --git a/src/routes/register/+page.server.js b/src/routes/register/+page.server.js
index 51de25e2..4121b671 100644
--- a/src/routes/register/+page.server.js
+++ b/src/routes/register/+page.server.js
@@ -1,16 +1,11 @@
import { post } from '$lib/utils';
+import { error } from '@sveltejs/kit';
export async function POST({ request }) {
try {
let user = await request.json();
- let body = await post('/register', { user });
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
- return { body };
+ await post('/register', { user });
} catch (e) {
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
- return {
- status: 500,
- body: e
- };
+ throw error(500, e.message);
}
}
diff --git a/src/routes/withdraw/+server.js b/src/routes/withdraw/+server.js
index 3b22a592..3f34b023 100644
--- a/src/routes/withdraw/+server.js
+++ b/src/routes/withdraw/+server.js
@@ -1,13 +1,9 @@
-import { json as json$1 } from '@sveltejs/kit';
import { post } from '$lib/utils';
+
export async function POST({ locals, request }) {
let { token } = locals;
let body = await request.json();
- body = await post('/lightning/send', body, {
+ await post('/lightning/send', body, {
authorization: `Bearer ${token}`
});
- throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292701)");
- // Suggestion (check for correctness before using):
- // return json$1(body);
- return { body };
}