Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ try {
```typescript Backend Verification
import { createPublicClient, http } from 'viem';
import { base } from 'viem/chains';
import { verifySiweMessage } from 'viem/siwe';

const client = createPublicClient({
chain: base,
Expand All @@ -89,11 +90,15 @@ export async function verifyAuthentication(req, res) {

try {
// Verify the signature
const isValid = await client.verifyMessage({
address,
message,
signature
});
// Nonce'u mesajın içinden çıkarıyoruz
const nonce = message.match(/Nonce: (\w+)/)?.[1];
const { isValid } = await verifySiweMessage(client, {
address,
message,
signature,
domain: req.headers.host ?? 'yourapp.com',
nonce: nonce,
});

if (!isValid) {
return res.status(401).json({
Expand Down Expand Up @@ -172,11 +177,14 @@ export async function verifyAuth(req, res) {
}

// Verify signature
const isValid = await client.verifyMessage({
address,
message,
signature
});
// Nonce daha önce 'extractNonceFromMessage' ile çıkarılmıştı
const { isValid } = await verifySiweMessage(client, {
address,
message,
signature,
domain: req.headers.host ?? 'yourapp.com',
nonce: nonce,
});

if (isValid) {
usedNonces.add(nonce);
Expand Down Expand Up @@ -221,11 +229,15 @@ app.post('/auth/verify', async (req, res) => {
}

// Verify signature
const valid = await client.verifyMessage({
address,
message,
signature
});
// Nonce daha önce 'message.match' ile çıkarılmıştı
const { isValid } = await verifySiweMessage(client, {
address,
message,
signature,
domain: req.headers.host ?? 'yourapp.com',
nonce: nonce,
});
const valid = isValid; // Eski kodla uyumlu olması için

if (!valid) {
return res.status(401).json({
Expand Down