blob: c260b7daef027171bde8d719c6e852cc3266f1db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import { auth, post } from "$lib/utils";
import { error } from "@sveltejs/kit";
export async function POST({ cookies, request }) {
try {
const body = await request.json();
const { username, secret } = await post("/otpsecret", body, auth(cookies));
const uri = `otpauth://totp/coinos:${username}?secret=${secret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`;
return new Response(JSON.stringify({ secret, uri }));
} catch (e: any) {
if (e.message.includes("pin")) throw e;
error(500, "Problem saving secret");
}
}
|