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() { 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
@ -182,9 +184,9 @@ class Daemon {
this.fastify.listen({ port: this.config.authPort }); this.fastify.listen({ port: this.config.authPort });
this.fastify.get('/requests/:id', authorizeRequestWebHandler); this.fastify.get(`${path}/requests/:id`, authorizeRequestWebHandler);
this.fastify.post('/requests/:id', processRequestWebHandler); this.fastify.post(`${path}/requests/:id`, processRequestWebHandler);
this.fastify.post('/register/:id', processRegistrationWebHandler); this.fastify.post(`${path}/register/:id`, processRegistrationWebHandler);
} }
async startKeys() { async startKeys() {

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] || '/'; 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] || '/'; 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

View File

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

View File

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

View File

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

View File

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

View File

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