Skip to content

Commit

Permalink
chore: tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
magiziz committed May 28, 2024
1 parent 5966b18 commit c9f5055
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/with-next-siwe-iron-session/pages/api/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
import { ironOptions } from './../../lib/iron';
import { publicActions } from 'viem';
import { wagmiConfig } from '../_app';
import { parseSiweMessage } from 'viem/siwe';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { method } = req;
Expand All @@ -23,6 +24,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
throw new Error('Invalid message');
}

if (parseSiweMessage(message).nonce !== req.session.nonce)
return res.status(422).json({ message: 'Invalid nonce.' });

req.session.siwe = { address };
await req.session.save();
res.json({ ok: true });
Expand Down

0 comments on commit c9f5055

Please sign in to comment.