From c011ed5a2f45379aafd79b0e6fd3a87b64287651 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 25 Aug 2022 08:59:47 -0700 Subject: fix withdrawals --- src/lib/utils.js | 5 +++++ src/routes/invoice/+server.js | 10 +++------- src/routes/withdraw/+server.js | 11 +++++------ 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src') 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' } }); } -- cgit v1.2.3