From a005ef51ee46618a1875dee4559ccddfec41dfcd Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 21 Oct 2022 13:29:04 -0700 Subject: move 2fa to separate step --- src/lib/utils.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/lib/utils.js') diff --git a/src/lib/utils.js b/src/lib/utils.js index 76ce5077..7cb09c61 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -36,6 +36,7 @@ export const post = (url, body, headers) => { return fetch(base + url, { method: 'POST', body: JSON.stringify(body), headers }) .then((r) => r.text()) .then((body) => { + console.log('BODY', body); try { body = JSON.parse(body); } catch (e) { @@ -108,7 +109,17 @@ export const info = (m) => { export const login = async (user, cookies) => { let maxAge = 30 * 24 * 60 * 60; - let { token } = await post('/login', user); + let res = await fetch(base + '/login', { + method: 'POST', + body: JSON.stringify(user), + headers: { 'content-type': 'application/json', accept: 'application/json' } + }); + if (res.status === 401) { + let text = await res.text(); + if (text.startsWith('2fa')) throw new Error('2fa'); + } + + let { token } = await res.json(); if (!token) throw new Error('Login failed'); let expires = new Date(); -- cgit v1.2.3