From eb53b5250fd33b5f5eaea29af631d778d849b60a Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 22 Jan 2024 08:50:28 +0700 Subject: [PATCH 01/16] redesign sign up and login pages --- templates/createAccount.handlebar | 252 +++++++++++++++++++----------- templates/login.handlebar | 130 ++++++++++----- 2 files changed, 250 insertions(+), 132 deletions(-) diff --git a/templates/createAccount.handlebar b/templates/createAccount.handlebar index 11e2069..3d442ac 100644 --- a/templates/createAccount.handlebar +++ b/templates/createAccount.handlebar @@ -1,112 +1,180 @@ - + + - - Document + Create Account - Nostr - - - + + - - - -
-
-

- - Welcome to Nostr! -

+ + +
+
+

+ Complete Creating Account +

+
+
+ {{#if error}} + + {{/if}} - - {{#if error}} - - {{/if}} + - + - + - + - + + - - - -
+ +
- + \ No newline at end of file diff --git a/templates/login.handlebar b/templates/login.handlebar index ca4e90a..48775ee 100644 --- a/templates/login.handlebar +++ b/templates/login.handlebar @@ -1,49 +1,99 @@ - + + - Login - Nostr - - + + + - - -
-
-

- - Login to Nostr -

-
+ + +
+
+

+ Login to Nostr Account +

+
+
- -
- -
-
- -
-
- -
-
+ + + + + +
- - + + + \ No newline at end of file From 13157d25d291a68df57cb3e34017f43b9b824362 Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 22 Jan 2024 09:05:27 +0700 Subject: [PATCH 02/16] update design for authorize page --- templates/authorizeRequest.handlebar | 183 ++++++++++++--------------- 1 file changed, 80 insertions(+), 103 deletions(-) diff --git a/templates/authorizeRequest.handlebar b/templates/authorizeRequest.handlebar index 1b2f40e..e952c0c 100644 --- a/templates/authorizeRequest.handlebar +++ b/templates/authorizeRequest.handlebar @@ -1,131 +1,108 @@ - + + - - Document + Authorize Request - Nostr - - - - + - - - - -
-

- + + +
+
+

+ Do you want to allow this client to use account +
+ {{record.keyName}}?

-
-
-

Do you want to allow this client to use account -
- {{record.keyName}}?

- @@ -128,9 +128,9 @@ type="text" name="username" value="{{username}}" - class="w-full relative text-sm text-blue-500 dark:text-neutral-200 bg-neutral-200 dark:bg-neutral-750 placeholder:text-neutral-400 dark:placeholder:text-neutral-500 px-3.5 py-2 rounded-lg border-none" /> + class="w-full relative text-sm text-blue-500 dark:text-blue-500 bg-neutral-200 dark:bg-neutral-800 placeholder:text-neutral-400 dark:placeholder:text-neutral-500 px-3.5 py-2 rounded-lg border-none" /> + class="text-neutral-500 text-sm absolute right-4 top-1/2 transform -translate-y-1/2"> @{{domain}}
diff --git a/templates/login.handlebar b/templates/login.handlebar index 48775ee..1f67731 100644 --- a/templates/login.handlebar +++ b/templates/login.handlebar @@ -89,7 +89,7 @@ From d89b0081d05936c0879c9d18700dd04a7f8a7e9b Mon Sep 17 00:00:00 2001 From: reya Date: Mon, 22 Jan 2024 09:17:49 +0700 Subject: [PATCH 04/16] remove duplicate style --- templates/authorizeRequest.handlebar | 4 ++-- templates/createAccount.handlebar | 2 +- templates/login.handlebar | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/authorizeRequest.handlebar b/templates/authorizeRequest.handlebar index 5704c44..0e741b3 100644 --- a/templates/authorizeRequest.handlebar +++ b/templates/authorizeRequest.handlebar @@ -78,11 +78,11 @@
diff --git a/templates/createAccount.handlebar b/templates/createAccount.handlebar index 19fda8a..a262918 100644 --- a/templates/createAccount.handlebar +++ b/templates/createAccount.handlebar @@ -171,7 +171,7 @@ diff --git a/templates/login.handlebar b/templates/login.handlebar index 1f67731..dd43dc8 100644 --- a/templates/login.handlebar +++ b/templates/login.handlebar @@ -89,7 +89,7 @@ From eed1baf79ab76a89941c289254243f764ddb3e87 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 23 Jan 2024 13:20:37 +0700 Subject: [PATCH 05/16] update styles --- templates/authorizeRequest.handlebar | 10 +- templates/createAccount.handlebar | 2 +- templates/error.handlebar | 70 +++++++++----- templates/login.handlebar | 2 +- templates/redirect.handlebar | 139 +++++++++++++++------------ 5 files changed, 129 insertions(+), 94 deletions(-) diff --git a/templates/authorizeRequest.handlebar b/templates/authorizeRequest.handlebar index 0e741b3..c5beec5 100644 --- a/templates/authorizeRequest.handlebar +++ b/templates/authorizeRequest.handlebar @@ -77,12 +77,14 @@ {{/unless}}
- -
diff --git a/templates/createAccount.handlebar b/templates/createAccount.handlebar index a262918..3cc84c3 100644 --- a/templates/createAccount.handlebar +++ b/templates/createAccount.handlebar @@ -171,7 +171,7 @@ diff --git a/templates/error.handlebar b/templates/error.handlebar index 96d5b6b..194070a 100644 --- a/templates/error.handlebar +++ b/templates/error.handlebar @@ -1,33 +1,53 @@ - + - - Login - Nostr - - + Login Error - Nostr + + + - - -
-
-

- - Login to Nostr -

-
- -
- {{error}} -
+ + +
+
+ {{error}} +
- + diff --git a/templates/login.handlebar b/templates/login.handlebar index dd43dc8..a30a8c0 100644 --- a/templates/login.handlebar +++ b/templates/login.handlebar @@ -89,7 +89,7 @@ diff --git a/templates/redirect.handlebar b/templates/redirect.handlebar index 5389a3f..1da1f08 100644 --- a/templates/redirect.handlebar +++ b/templates/redirect.handlebar @@ -1,78 +1,91 @@ - + + - - Document + Redirect - Nostr - - - - + + - - - -
+ + +
+
+ {{#if callbackUrl}}
-

- - Welcome to Nostr! -

+

+ You are being redirected to {{callbackUrl}} +

- -
- {{#if callbackUrl}} -
-

- You are being redirected to {{callbackUrl}} -

-
- -
-

- If you are not redirected automatically, follow this link -

-
- {{else}} -
-

- You can close this window now. -

-
- - - {{/if}} +
+

+ If you are not redirected automatically, follow this link +

+ {{else}} +
+

+ You can close this window now. +

+ +
+ {{/if}} +
- + \ No newline at end of file From 67f43d95af917a670ee1bc4d27a1358567ee132a Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 23 Jan 2024 13:35:28 +0700 Subject: [PATCH 06/16] add base url to template --- src/daemon/web/authorize.ts | 3 ++- templates/createAccount.handlebar | 2 +- templates/login.handlebar | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/daemon/web/authorize.ts b/src/daemon/web/authorize.ts index e54fa2a..589a5ee 100644 --- a/src/daemon/web/authorize.ts +++ b/src/daemon/web/authorize.ts @@ -163,6 +163,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]; // we serialize the payload again and store it // along with the allowed flag @@ -179,7 +180,7 @@ export async function processRegistrationWebHandler(request, reply) { const [ username, domain, email ] = JSON.parse(record.params!); const nip05 = `${username}@${domain}`; - return reply.view("/templates/createAccount.handlebar", { record, email, username, domain, nip05, error: e.message}); + return reply.view("/templates/createAccount.handlebar", { baseUrl, record, email, username, domain, nip05, error: e.message}); } await prisma.request.update({ diff --git a/templates/createAccount.handlebar b/templates/createAccount.handlebar index 3cc84c3..fe578e1 100644 --- a/templates/createAccount.handlebar +++ b/templates/createAccount.handlebar @@ -87,7 +87,7 @@

{{#if error}} diff --git a/templates/login.handlebar b/templates/login.handlebar index a30a8c0..446e2d4 100644 --- a/templates/login.handlebar +++ b/templates/login.handlebar @@ -52,7 +52,7 @@
From 129cb996733be19ed9c8d4bd54f926dd7cf45049 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 23 Jan 2024 13:44:18 +0700 Subject: [PATCH 07/16] fix --- src/daemon/web/authorize.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/daemon/web/authorize.ts b/src/daemon/web/authorize.ts index 589a5ee..4bf3ee0 100644 --- a/src/daemon/web/authorize.ts +++ b/src/daemon/web/authorize.ts @@ -49,6 +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 method = record.method; let nip05: string | undefined; @@ -59,7 +60,7 @@ export async function authorizeRequestWebHandler(request, reply) { const [ username, domain, email ] = JSON.parse(record.params!); nip05 = `${username}@${domain}`; - return reply.view("/templates/createAccount.handlebar", { record, email, username, domain, nip05, callbackUrl }); + return reply.view("/templates/createAccount.handlebar", { baseUrl, record, email, username, domain, nip05, callbackUrl }); } else { const authorized = validateAuthCookie(request); return reply.view("/templates/authorizeRequest.handlebar", { record, callbackUrl, authorized }); @@ -163,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] || ''; // we serialize the payload again and store it // along with the allowed flag From 7ee7e0cfff01ac528baf876c88590d9bb23fe955 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 23 Jan 2024 13:47:15 +0700 Subject: [PATCH 08/16] fix again --- src/daemon/web/authorize.ts | 4 ++-- templates/createAccount.handlebar | 2 +- templates/login.handlebar | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/daemon/web/authorize.ts b/src/daemon/web/authorize.ts index 4bf3ee0..95798c0 100644 --- a/src/daemon/web/authorize.ts +++ b/src/daemon/web/authorize.ts @@ -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] || '/'; 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] || '/'; // we serialize the payload again and store it // along with the allowed flag diff --git a/templates/createAccount.handlebar b/templates/createAccount.handlebar index fe578e1..65a1ceb 100644 --- a/templates/createAccount.handlebar +++ b/templates/createAccount.handlebar @@ -87,7 +87,7 @@
{{#if error}} diff --git a/templates/login.handlebar b/templates/login.handlebar index 446e2d4..cdee223 100644 --- a/templates/login.handlebar +++ b/templates/login.handlebar @@ -52,7 +52,7 @@
From 30ab41907d3d02836f3bc9e32e5f821a9024c7f6 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 23 Jan 2024 13:54:15 +0700 Subject: [PATCH 09/16] fix --- src/daemon/run.ts | 8 +++++--- src/daemon/web/authorize.ts | 4 ++-- templates/authorizeRequest.handlebar | 2 +- templates/createAccount.handlebar | 2 +- templates/error.handlebar | 2 +- templates/login.handlebar | 2 +- templates/redirect.handlebar | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/daemon/run.ts b/src/daemon/run.ts index 19f3e65..ca7a90f 100644 --- a/src/daemon/run.ts +++ b/src/daemon/run.ts @@ -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() { diff --git a/src/daemon/web/authorize.ts b/src/daemon/web/authorize.ts index 95798c0..868e347 100644 --- a/src/daemon/web/authorize.ts +++ b/src/daemon/web/authorize.ts @@ -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 diff --git a/templates/authorizeRequest.handlebar b/templates/authorizeRequest.handlebar index c5beec5..dcff0ea 100644 --- a/templates/authorizeRequest.handlebar +++ b/templates/authorizeRequest.handlebar @@ -3,7 +3,7 @@ - Authorize Request - Nostr + Authorize Request