This commit is contained in:
reya 2024-01-23 13:54:15 +07:00
parent 7ee7e0cfff
commit 30ab41907d
7 changed files with 12 additions and 10 deletions

View File

@ -174,6 +174,8 @@ class Daemon {
async startWebAuth() {
if (!this.config.authPort) return;
const path = new URL(this.config.baseUrl as string).pathname.replace(/\/+$/, '');
this.fastify.register(FastifyView, {
engine: {
handlebars: Handlebars
@ -182,9 +184,9 @@ class Daemon {
this.fastify.listen({ port: this.config.authPort });
this.fastify.get('/requests/:id', authorizeRequestWebHandler);
this.fastify.post('/requests/:id', processRequestWebHandler);
this.fastify.post('/register/:id', processRegistrationWebHandler);
this.fastify.get(`${path}/requests/:id`, authorizeRequestWebHandler);
this.fastify.post(`${path}/requests/:id`, processRequestWebHandler);
this.fastify.post(`${path}/register/:id`, processRegistrationWebHandler);
}
async startKeys() {

View File

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

View File

@ -3,7 +3,7 @@
<head>
<meta name="robots" content="noindex">
<meta charset="UTF-8">
<title>Authorize Request - Nostr</title>
<title>Authorize Request</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com?plugins=forms"></script>
<script>

View File

@ -87,7 +87,7 @@
</h1>
</div>
<form
action="{{baseUrl}}register/{{record.id}}"
action="{{baseUrl}}/register/{{record.id}}"
method="POST"
class="w-full flex flex-col gap-5">
{{#if error}}

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Error - Nostr</title>
<title>Error</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com?plugins=forms"></script>
<script>

View File

@ -52,7 +52,7 @@
</h1>
</div>
<form
action="{{baseUrl}}login"
action="{{baseUrl}}/login"
method="POST"
class="w-full flex flex-col gap-5">

View File

@ -3,7 +3,7 @@
<head>
<meta name="robots" content="noindex">
<meta charset="UTF-8">
<title>Redirect - Nostr</title>
<title>Redirect</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.tailwindcss.com?plugins=forms"></script>
<script>