fix again

This commit is contained in:
reya 2024-01-23 14:06:52 +07:00
commit 65e067505b
2 changed files with 7 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import NDK, { NDKEvent, NDKNip46Backend, NDKPrivateKeySigner, Nip46PermitCallback, Nip46PermitCallbackParams, NostrEvent } from '@nostr-dev-kit/ndk'; import NDK, { NDKPrivateKeySigner, Nip46PermitCallback, Nip46PermitCallbackParams } from '@nostr-dev-kit/ndk';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { Backend } from './backend/index.js'; import { Backend } from './backend/index.js';
import { import {
@ -174,8 +174,6 @@ class Daemon {
async startWebAuth() { async startWebAuth() {
if (!this.config.authPort) return; if (!this.config.authPort) return;
const path = new URL(this.config.baseUrl as string).pathname.replace(/\/+$/, '');
this.fastify.register(FastifyView, { this.fastify.register(FastifyView, {
engine: { engine: {
handlebars: Handlebars handlebars: Handlebars
@ -184,9 +182,9 @@ class Daemon {
this.fastify.listen({ port: this.config.authPort }); this.fastify.listen({ port: this.config.authPort });
this.fastify.get(`${path}/requests/:id`, authorizeRequestWebHandler); this.fastify.get('/requests/:id', authorizeRequestWebHandler);
this.fastify.post(`${path}/requests/:id`, processRequestWebHandler); this.fastify.post('/requests/:id', processRequestWebHandler);
this.fastify.post(`${path}/register/:id`, processRegistrationWebHandler); this.fastify.post('/register/:id', processRegistrationWebHandler);
} }
async startKeys() { async startKeys() {
@ -204,7 +202,7 @@ class Daemon {
} }
const nsec = nip19.nsecEncode(settings.key); const nsec = nip19.nsecEncode(settings.key);
await this.loadNsec(keyName, nsec); this.loadNsec(keyName, nsec);
} }
} }

View file

@ -49,7 +49,7 @@ export async function authorizeRequestWebHandler(request, reply) {
const record = await getAndValidateStateOfRequest(request); const record = await getAndValidateStateOfRequest(request);
const url = new URL(request.url, `http://${request.headers.host}`); const url = new URL(request.url, `http://${request.headers.host}`);
const callbackUrl = url.searchParams.get("callbackUrl"); const callbackUrl = url.searchParams.get("callbackUrl");
const baseUrl = new URL(request.url).pathname?.split('/')?.[1]?.replace(/\/+$/, '') || '/'; const baseUrl = new URL(request.url).pathname?.split('/')?.[1]?.replace(/\/+$/, '');
const method = record.method; const method = record.method;
let nip05: string | undefined; let nip05: string | undefined;
@ -164,7 +164,7 @@ export async function processRegistrationWebHandler(request, reply) {
try { try {
const record = await getAndValidateStateOfRequest(request); const record = await getAndValidateStateOfRequest(request);
const body = request.body; const body = request.body;
const baseUrl = new URL(request.url).pathname?.split('/')?.[1]?.replace(/\/+$/, '') || '/'; const baseUrl = new URL(request.url).pathname?.split('/')?.[1]?.replace(/\/+$/, '');
// we serialize the payload again and store it // we serialize the payload again and store it
// along with the allowed flag // along with the allowed flag