redirect to callback on auth

This commit is contained in:
Pablo Fernandez
2024-01-02 13:54:56 +00:00
parent fddc592f50
commit d9c07c0115
2 changed files with 20 additions and 3 deletions

View File

@@ -53,6 +53,8 @@ export async function authorizeRequestWebHandler(request, reply) {
const method = record.method; const method = record.method;
let nip05: string | undefined; let nip05: string | undefined;
debug({callbackUrl})
if (method === "create_account") { if (method === "create_account") {
const [ username, domain, email ] = JSON.parse(record.params!); const [ username, domain, email ] = JSON.parse(record.params!);
nip05 = `${username}@${domain}`; nip05 = `${username}@${domain}`;
@@ -102,6 +104,8 @@ export async function validateRequest(request, record) {
debug("Provided password didn't match") debug("Provided password didn't match")
throw new Error("Invalid password"); throw new Error("Invalid password");
} }
return userRecord;
} }
export async function processRequestWebHandler(request, reply) { export async function processRequestWebHandler(request, reply) {
@@ -113,8 +117,10 @@ export async function processRequestWebHandler(request, reply) {
return; return;
} }
let userRecord;
try { try {
await validateRequest(request, record); userRecord = await validateRequest(request, record);
} catch (e: any) { } catch (e: any) {
reply.status(401); reply.status(401);
reply.type("application/json"); reply.type("application/json");
@@ -150,7 +156,7 @@ export async function processRequestWebHandler(request, reply) {
); );
} }
return { ok: true }; return { ok: true, pubkey: userRecord.pubkey };
} }
export async function processRegistrationWebHandler(request, reply) { export async function processRegistrationWebHandler(request, reply) {

View File

@@ -13,9 +13,13 @@
function sendPostRequest(permissions) { function sendPostRequest(permissions) {
const url = '/requests/{{record.id}}'; const url = '/requests/{{record.id}}';
const password = document.getElementById('password').value; const password = document.getElementById('password').value;
let callbackUrl;
{{#if callbackUrl}}
callbackUrl = '{{callbackUrl}}';
{{/if}}
const data = { const data = {
permissions, permissions,
password password,
}; };
fetch(url, { fetch(url, {
@@ -38,6 +42,13 @@
// hide main content and show close message // hide main content and show close message
document.getElementById('main').classList.add('hidden'); document.getElementById('main').classList.add('hidden');
document.getElementById('closeit').classList.remove('hidden'); document.getElementById('closeit').classList.remove('hidden');
// redirect to callback url
if (callbackUrl) {
const url = new URL(callbackUrl);
url.searchParams.append('pubkey', data.pubkey);
window.location.href = url.toString();
}
}) })
.catch((error) => { .catch((error) => {
console.error('Error:', error); console.error('Error:', error);