-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from cardano2vn/fix-login
update
- Loading branch information
Showing
8 changed files
with
75 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
prisma/migrations/20241106020243_add_table_wallet_nonce/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- CreateTable | ||
CREATE TABLE "wallet_nonce" ( | ||
"id" TEXT NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
"address" TEXT NOT NULL, | ||
"nonce" TEXT NOT NULL, | ||
|
||
CONSTRAINT "wallet_nonce_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "wallet_nonce_address_key" ON "wallet_nonce"("address"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,46 @@ | ||
"use server"; | ||
|
||
import prisma from "@/lib/prisma"; | ||
import { generateNonce } from "@meshsdk/core"; | ||
import { isNil } from "lodash"; | ||
|
||
export const getNonceByAddress = async (address: string) => { | ||
if (isNil(address)) { | ||
throw new Error("Stake address is required"); | ||
} | ||
try { | ||
if (isNil(address)) { | ||
throw new Error("Stake address is required"); | ||
} | ||
|
||
if (!/^[a-z0-9_]+$/.test(address)) { | ||
throw new Error("Invalid address"); | ||
} | ||
if (!/^[a-z0-9_]+$/.test(address)) { | ||
throw new Error("Invalid address"); | ||
} | ||
|
||
// const nonce = generateNonce("signin to cip68 nft"); | ||
// const walletNonce = await prisma.walletNonce.upsert({ | ||
// where: { | ||
// address: address, | ||
// }, | ||
// create: { | ||
// address: address, | ||
// nonce: nonce, | ||
// }, | ||
// update: { | ||
// nonce: nonce, | ||
// }, | ||
// }); | ||
const nonce = generateNonce("signin to cip68 nft"); | ||
const walletNonce = await prisma.walletNonce.upsert({ | ||
where: { | ||
address: address, | ||
}, | ||
create: { | ||
address: address, | ||
nonce: nonce, | ||
}, | ||
update: { | ||
nonce: nonce, | ||
}, | ||
}); | ||
if (!walletNonce) { | ||
throw new Error("Cannot get the nonce"); | ||
} | ||
|
||
const nonce = await global.cacheUser.get(`nonce-${address}`); | ||
if (nonce) { | ||
return nonce; | ||
} | ||
const newNonce = generateNonce("signin to cip68 nft"); | ||
const setCache = await global.cacheUser.set(`nonce-${address}`, newNonce); | ||
if (!setCache) { | ||
throw new Error("Cannot get the nonce"); | ||
return { | ||
data: nonce, | ||
result: true, | ||
message: "Nonce generated successfully", | ||
}; | ||
} catch (e) { | ||
return { | ||
data: null, | ||
result: false, | ||
message: e instanceof Error ? e.message : "unknown error", | ||
}; | ||
} | ||
return newNonce; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters