add link directly into contact page to add a new contact via "contactJwt" query parameter

This commit is contained in:
2024-09-27 18:41:11 -06:00
parent 2942a02a4e
commit a271d9c206
13 changed files with 204 additions and 78 deletions

View File

@@ -299,6 +299,7 @@ import {
} from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import { getContactPayloadFromJwtUrl } from "@/libs/crypto";
import { decodeEndorserJwt } from "@/libs/crypto/vc";
import {
CONTACT_CSV_HEADER,
CONTACT_URL_PREFIX,
@@ -307,6 +308,7 @@ import {
isDid,
register,
setVisibilityUtil,
UserInfo,
} from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util";
import QuickNav from "@/components/QuickNav.vue";
@@ -374,6 +376,24 @@ export default class ContactsView extends Vue {
this.contacts = baseContacts.sort((a, b) =>
(a.name || "").localeCompare(b.name || ""),
);
const importedContactJwt = (this.$route as Router).query[
"contactJwt"
] as string;
if (importedContactJwt) {
// really should fully verify
const { payload } = decodeEndorserJwt(importedContactJwt);
const userInfo = payload["own"] as UserInfo;
const newContact = {
did: payload["iss"],
name: userInfo.name,
nextPubKeyHashB64: userInfo.nextPublicEncKeyHash,
profileImageUrl: userInfo.profileImageUrl,
publicKeyBase64: userInfo.publicEncKey,
registered: userInfo.registered,
} as Contact;
this.addContact(newContact);
}
}
private danger(message: string, title: string = "Error", timeout = 5000) {
@@ -891,7 +911,10 @@ export default class ContactsView extends Vue {
}
return true;
} else {
console.error("Got strange result from setting visibility:", result);
console.error(
"Got strange result from setting visibility. It can happen when setting visibility on oneself.",
result,
);
const message =
(result.error as string) || "Could not set visibility on the server.";
this.$notify(