diff --git a/identity-api/src/routes/auth/heirs.ts b/identity-api/src/routes/auth/heirs.ts index 3ce24cf..ff526a0 100644 --- a/identity-api/src/routes/auth/heirs.ts +++ b/identity-api/src/routes/auth/heirs.ts @@ -29,6 +29,35 @@ const Body = Type.Object({ type BodyType = Static; export default function register(app: AppInterface, auth: AuthInterface, database: DatabaseInterface) { + app.get("/auth/heirs", { + async handler(request, reply) { + let jwt = request.headers["authorization"].replace("Bearer", "").trim(); + let { payload } = await auth.verifyJwt(jwt); + + if (payload.uid == null) { + reply.status(401); + return; + } + + return (await database.listHeirs(payload.uid)) + .map((v) => { + v["contactMethod"] = "email"; + return v; + }) + .map((v) => { + v["value"] = v["email"]; + return v; + }) + .map((v) => { + v["email"] = undefined; + return v; + }); + }, + schema: { + headers: { $ref: "schema://identity/authorization" }, + }, + }); + app.put<{ Body: BodyType }>("/auth/heirs", { async handler(request, reply) { let jwt = request.headers["authorization"].replace("Bearer", "").trim(); diff --git a/identity-web/src/lib/api.ts b/identity-web/src/lib/api.ts index 3d47c8a..d784542 100644 --- a/identity-web/src/lib/api.ts +++ b/identity-web/src/lib/api.ts @@ -143,6 +143,10 @@ export async function removeHeir(credentials: Credentials, heirID: string): Prom })); } +export async function listHeirs(credentials: Credentials): Promise { + return await asJson(sendRequest('/auth/heirs', credentials)); +} + export async function uploadAsset(session_key: string, file: File): Promise { let url = new URL('/asset', ASSET_API_ENDPOINT); url.search = `?session_key=${session_key}`; diff --git a/identity-web/src/routes/auth/account/+page.svelte b/identity-web/src/routes/auth/account/+page.svelte index 2a6919c..4084742 100644 --- a/identity-web/src/routes/auth/account/+page.svelte +++ b/identity-web/src/routes/auth/account/+page.svelte @@ -5,27 +5,29 @@ @@ -63,119 +62,123 @@ Welcome back, {$account?.name} . -
-
-

Heirs

- {#if $account?.heirs.length > 0} - + {#await heirs} + Loading heirs... + {:then heirs} +
+
+

Heirs

+ {#if heirs.length > 0} + + {/if} +
+ {#if !heirWizard && heirs.length === 0} +
+ +
{/if} + {#if heirWizard} +
+
+
+ + + {#if $errors.contactMethod != null} +

+ {$errors.contactMethod[0]} +

+ {/if} +
+
+ + + {#if $errors.name != null} +

+ {$errors.name[0]} +

+ {/if} +
+
+ + + {#if $errors.contactDetails != null} +

+ {$errors.contactDetails[0]} +

+ {/if} +
+ +
+
+ {/if} + {#each heirs || [] as heir (heir.id)} +
+
+ + Contact method: {heir.contactMethod} + + +
+
+ {heir.name} + · + {heir.value} +
+
+ {/each}
- {#if !heirWizard && $account?.heirs.length === 0} -
- -
- {/if} - {#if heirWizard} -
-
-
- - - {#if $errors.contactMethod != null} -

- {$errors.contactMethod[0]} -

- {/if} -
-
- - - {#if $errors.name != null} -

- {$errors.name[0]} -

- {/if} -
-
- - - {#if $errors.contactDetails != null} -

- {$errors.contactDetails[0]} -

- {/if} -
- -
-
- {/if} - {#each $account?.heirs || [] as heir (heir.value)} -
-
- - Contact method: {heir.contactMethod} - - -
-
- {heir.name} - · - {heir.value} -
-
- {/each} -
+ {/await}