Merge branch 'dev' into feature/list-your-product-ui

This commit is contained in:
MTG2000
2022-08-19 21:06:01 +03:00
2 changed files with 37 additions and 18 deletions

View File

@@ -32,7 +32,6 @@ const loginHandler = async (req, res) => {
algorithms: ['HS256'],
})
const user_id = payload.user_id;
const existingKeys = await prisma.userKey.findMany({ where: { user_id }, select: { key: true } });
if (existingKeys.length >= 3)
@@ -42,7 +41,7 @@ const loginHandler = async (req, res) => {
return res.status(400).json({ status: 'ERROR', reason: "Wallet already linked" });
// Remove old linking for this key if existing
await prisma.userKey.delete({
await prisma.userKey.deleteMany({
where: { key }
})
@@ -69,25 +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,
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

View File

@@ -68,7 +68,8 @@ model User {
}
model UserKey {
key String @id
key String @id
name String @default("My new wallet key")
user User? @relation(fields: [user_id], references: [id])
user_id Int?