Generate and save nostr keypair for email users on first signin

This commit is contained in:
austinkelsay 2024-11-14 15:51:29 -06:00
parent a0560c420b
commit fda7d50b81
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02
3 changed files with 30 additions and 9 deletions

View File

@ -85,7 +85,7 @@ const UserProfile = () => {
<div className="relative flex w-full items-center justify-center">
<Image
alt="user's avatar"
src={returnImageProxy(user.avatar, user.pubkey)}
src={returnImageProxy(user.avatar, user?.pubkey || "")}
width={100}
height={100}
className="rounded-full my-4"
@ -108,10 +108,12 @@ const UserProfile = () => {
<h1 className="text-center text-2xl my-2">
{user.username || user?.email || "Anon"}
</h1>
<h2 className="text-center text-xl my-2 truncate max-tab:px-4 max-mob:px-4">
<Tooltip target=".pubkey-tooltip" content={"this is your nostr npub"} />
{nip19.npubEncode(user.pubkey)} <i className="pi pi-question-circle text-xl pubkey-tooltip" />
</h2>
{user.pubkey && (
<h2 className="text-center text-xl my-2 truncate max-tab:px-4 max-mob:px-4">
<Tooltip target=".pubkey-tooltip" content={"this is your nostr npub"} />
{nip19.npubEncode(user.pubkey)} <i className="pi pi-question-circle text-xl pubkey-tooltip" />
</h2>
)}
{user?.lightningAddress && (
<h3 className="w-fit mx-auto text-center text-xl my-2 bg-gray-800 rounded-lg p-4">
<span className="font-bold">Lightning Address:</span> {user.lightningAddress.name}@plebdevs.com <i className="pi pi-copy cursor-pointer hover:text-gray-400" onClick={() => copyToClipboard(user.lightningAddress.name + "@plebdevs.com")} />

View File

@ -192,7 +192,7 @@ const UserSettings = () => {
<div className="relative flex w-full items-center justify-center">
<Image
alt="user's avatar"
src={returnImageProxy(user.avatar, user.pubkey)}
src={returnImageProxy(user.avatar, user?.pubkey || "")}
width={100}
height={100}
className="rounded-full my-4"
@ -214,10 +214,12 @@ const UserSettings = () => {
<h1 className="text-center text-2xl my-2">
{user.username || user?.email || "Anon"}
</h1>
<h2 className="text-center text-xl my-2 truncate max-tab:px-4 max-mob:px-4">
<Tooltip target=".pubkey-tooltip" content={"this is your nostr npub"} />
{user.pubkey && (
<h2 className="text-center text-xl my-2 truncate max-tab:px-4 max-mob:px-4">
<Tooltip target=".pubkey-tooltip" content={"this is your nostr npub"} />
{nip19.npubEncode(user.pubkey)} <i className="pi pi-question-circle text-xl pubkey-tooltip" />
</h2>
</h2>
)}
{user?.lightningAddress && (
<h3 className="w-fit mx-auto text-center text-xl my-2 bg-gray-800 rounded-lg p-4">
<span className="font-bold">Lightning Address:</span> {user.lightningAddress.name}@plebdevs.com <i className="pi pi-copy cursor-pointer hover:text-gray-400" onClick={() => copyToClipboard(user.lightningAddress.name + "@plebdevs.com")} />

View File

@ -169,6 +169,23 @@ export const authOptions = {
token.user = newUser;
}
// if we sign up with email and we don't have a pubkey or privkey, we need to generate them
if (trigger === "signUp" && account?.provider === "email" && !user.pubkey && !user.privkey) {
const sk = generateSecretKey();
const pubkey = getPublicKey(sk);
const privkey = bytesToHex(sk);
// Update the user in the database
await prisma.user.update({
where: { id: user.id },
data: { pubkey, privkey }
});
// Update the user object
user.pubkey = pubkey;
user.privkey = privkey;
}
if (user) {
token.user = user;
if (user.pubkey && user.privkey) {