This commit is contained in:
reya
2024-01-23 14:24:52 +07:00
parent c28e58de88
commit f3b8aa8ebb
4 changed files with 8 additions and 9 deletions

View File

@@ -174,10 +174,13 @@ class Daemon {
async startWebAuth() { async startWebAuth() {
if (!this.config.authPort) return; if (!this.config.authPort) return;
const prefix = new URL(this.config.baseUrl as string).pathname.replace(/\/+$/, '');
this.fastify.register(FastifyView, { this.fastify.register(FastifyView, {
engine: { engine: {
handlebars: Handlebars handlebars: Handlebars
} },
prefix
}); });
this.fastify.listen({ port: this.config.authPort }); this.fastify.listen({ port: this.config.authPort });

View File

@@ -49,8 +49,6 @@ 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");
console.log(request)
const baseUrl = new URL(request.originalUrl).pathname.replace(/\/+$/, '');
const method = record.method; const method = record.method;
let nip05: string | undefined; let nip05: string | undefined;
@@ -61,7 +59,7 @@ export async function authorizeRequestWebHandler(request, reply) {
const [ username, domain, email ] = JSON.parse(record.params!); const [ username, domain, email ] = JSON.parse(record.params!);
nip05 = `${username}@${domain}`; nip05 = `${username}@${domain}`;
return reply.view("/templates/createAccount.handlebar", { baseUrl, record, email, username, domain, nip05, callbackUrl }); return reply.view("/templates/createAccount.handlebar", { record, email, username, domain, nip05, callbackUrl });
} else { } else {
const authorized = validateAuthCookie(request); const authorized = validateAuthCookie(request);
return reply.view("/templates/authorizeRequest.handlebar", { record, callbackUrl, authorized }); return reply.view("/templates/authorizeRequest.handlebar", { record, callbackUrl, authorized });
@@ -165,8 +163,6 @@ 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;
console.log(request)
const baseUrl = new URL(request.originalUrl).pathname.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
@@ -183,7 +179,7 @@ export async function processRegistrationWebHandler(request, reply) {
const [ username, domain, email ] = JSON.parse(record.params!); const [ username, domain, email ] = JSON.parse(record.params!);
const nip05 = `${username}@${domain}`; const nip05 = `${username}@${domain}`;
return reply.view("/templates/createAccount.handlebar", { baseUrl, record, email, username, domain, nip05, error: e.message}); return reply.view("/templates/createAccount.handlebar", { record, email, username, domain, nip05, error: e.message});
} }
await prisma.request.update({ await prisma.request.update({

View File

@@ -87,7 +87,7 @@
</h1> </h1>
</div> </div>
<form <form
action="{{baseUrl}}/register/{{record.id}}" action="/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

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