From 9baf0ecabae1b32a74b29c7dd65bf6ffd67525e4 Mon Sep 17 00:00:00 2001 From: Davinci Date: Thu, 16 May 2024 17:15:21 +0200 Subject: [PATCH] fix: robohash image missing with NIP05 login --- src/controllers/AuthController.ts | 38 +++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/controllers/AuthController.ts b/src/controllers/AuthController.ts index 4eb2ac7..7e1c00d 100644 --- a/src/controllers/AuthController.ts +++ b/src/controllers/AuthController.ts @@ -32,20 +32,44 @@ export class AuthController { * or error if otherwise */ async authenticateAndFindMetadata(pubkey: string) { + const emptyMetadata = this.metadataController.getEmptyMetadataEvent() + + emptyMetadata.content = JSON.stringify({ + picture: getRoboHashPicture(pubkey) + }) + this.metadataController .findMetadata(pubkey) .then((event) => { - store.dispatch(setMetadataEvent(event)) + if (event) { + // In case of NIP05 there is scenario where login content will be populated but without an image + // In such case we will add robohash image + if (event.content) { + const content = JSON.parse(event.content) + + if (!content) { + event.content = '' + } + + if (!content.picture) { + content.picture = getRoboHashPicture(pubkey) + } + + event.content = JSON.stringify(content) + } else { + event.content = JSON.stringify({ + picture: getRoboHashPicture(pubkey) + }) + } + + store.dispatch(setMetadataEvent(event)) + } else { + store.dispatch(setMetadataEvent(emptyMetadata)) + } }) .catch((err) => { console.warn('Error occurred while finding metadata', err) - const emptyMetadata = this.metadataController.getEmptyMetadataEvent() - - emptyMetadata.content = JSON.stringify({ - picture: getRoboHashPicture(pubkey) - }) - store.dispatch(setMetadataEvent(emptyMetadata)) }) -- 2.34.1