udpate: handle old account same wallet

This commit is contained in:
MTG2000
2022-08-19 20:35:09 +03:00
parent ec10c75063
commit 20e2b1ea75

View File

@@ -68,26 +68,44 @@ const loginHandler = async (req, res) => {
const user = await getUserByPubKey(key)
if (user === null) {
const nostr_prv_key = generatePrivateKey();
const nostr_pub_key = getPublicKey(nostr_prv_key);
// Check if user had a previous account using this wallet
const createdUser = await prisma.user.create({
data: {
pubKey: key,
name: key,
avatar: `https://avatars.dicebear.com/api/bottts/${key}.svg`,
nostr_prv_key,
nostr_pub_key,
},
})
await prisma.userKey.create({
data: {
key,
name: "My original wallet key",
user_id: createdUser.id,
const oldAccount = await prisma.user.findFirst({
where: {
pubKey: key
}
});
if (oldAccount) {
await prisma.userKey.create({
data: {
key,
name: "My original wallet key",
user_id: oldAccount.id,
}
});
} else {
const nostr_prv_key = generatePrivateKey();
const nostr_pub_key = getPublicKey(nostr_prv_key);
const createdUser = await prisma.user.create({
data: {
pubKey: key,
name: key,
avatar: `https://avatars.dicebear.com/api/bottts/${key}.svg`,
nostr_prv_key,
nostr_pub_key,
},
})
await prisma.userKey.create({
data: {
key,
name: "My original wallet key",
user_id: createdUser.id,
}
});
}
}
// calc the hash of k1