module.exports = (stream, func) => { var remaining = ""; stream.on("data", function (data) { remaining += data; var index = remaining.indexOf("\n"); var last = 0; while (index > -1) { var line = remaining.substring(last, index); last = index + 1; func(line); index = remaining.indexOf("\n", last); } remaining = remaining.substring(last); }); stream.on("error", () => {}); stream.on("end", function () { if (remaining.length > 0) { func(remaining); } }); }; ad>
aboutsummaryrefslogblamecommitdiffstats
path: root/src/routes/(app)/otpsecret/+server.js
blob: cdd050c831099cfdf418f69060b60ca01ea60f4f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                                        
                                      

                                                          






                                                                                                                                           
 
import { auth, post } from '$lib/utils';
import Qr from 'qrcode-base64';
import { error } from '@sveltejs/kit';

export async function POST({ cookies, locals, request }) {
	try {
		let { secret } = await post('/otpsecret', await request.json(), auth(cookies));
		let uri = `otpauth://totp/coinos:${locals.user.username}?secret=${secret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`;
		return new Response(JSON.stringify({ secret, uri, qr: Qr.drawImg(uri, { size: 600 }) }));
	} catch (e) {
		throw new error(500, 'Problem saving secret');
	}
}