aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-08-25 08:59:47 -0700
committerAdam Soltys <[email protected]>2022-08-25 08:59:49 -0700
commitc011ed5a2f45379aafd79b0e6fd3a87b64287651 (patch)
treee875e84879e54109ec4c687f576fd2d74763c0fc /src
parent42e8425d9066e014ef8236a58b68780f763c59cf (diff)
downloadcoinos-ui-c011ed5a2f45379aafd79b0e6fd3a87b64287651.tar.gz
coinos-ui-c011ed5a2f45379aafd79b0e6fd3a87b64287651.zip
fix withdrawals
Diffstat (limited to 'src')
-rw-r--r--src/lib/utils.js5
-rw-r--r--src/routes/invoice/+server.js10
-rw-r--r--src/routes/withdraw/+server.js11
3 files changed, 13 insertions, 13 deletions
diff --git a/src/lib/utils.js b/src/lib/utils.js
index 65025c3a..712ce8f5 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -126,3 +126,8 @@ export const login = async (user, setHeaders) => {
})
});
};
+
+export const auth = (req) => {
+ let { token } = cookie.parse(req.headers.get('cookie') || '');
+ return { authorization: `Bearer ${token}` };
+};
diff --git a/src/routes/invoice/+server.js b/src/routes/invoice/+server.js
index 3942904b..a4c4f9c8 100644
--- a/src/routes/invoice/+server.js
+++ b/src/routes/invoice/+server.js
@@ -1,16 +1,12 @@
-import cookie from 'cookie';
-import { get, post } from '$lib/utils';
+import { auth, get, post } from '$lib/utils';
export async function POST({ request }) {
- let { token } = cookie.parse(request.headers.get('cookie') || '');
-
let network = 'lightning';
let { amount, currency, rate, tip, text, username } = await request.json();
- let headers = { authorization: `Bearer ${token}` };
- ({ text } = await post('/lightning/invoice', { amount }, headers));
+ ({ text } = await post('/lightning/invoice', { amount }, auth(request)));
let invoice = { amount, currency, network, rate, tip, text };
- let { uuid } = await post('/invoice', { invoice, user: { username } }, headers);
+ let { uuid } = await post('/invoice', { invoice, user: { username } }, auth(request));
return new Response(JSON.stringify(uuid), { headers: { 'content-type': 'application/json' } });
}
diff --git a/src/routes/withdraw/+server.js b/src/routes/withdraw/+server.js
index 3f34b023..ed6e74ed 100644
--- a/src/routes/withdraw/+server.js
+++ b/src/routes/withdraw/+server.js
@@ -1,9 +1,8 @@
-import { post } from '$lib/utils';
+import { auth, post } from '$lib/utils';
-export async function POST({ locals, request }) {
- let { token } = locals;
+export async function POST({ request }) {
let body = await request.json();
- await post('/lightning/send', body, {
- authorization: `Bearer ${token}`
- });
+ await post('/lightning/send', body, auth(request));
+
+ return new Response(JSON.stringify("ok"), { headers: { 'content-type': 'application/json' } });
}