Skip to content

Commit 15f5367

Browse files
committed
feat: add better validation error message
1 parent de0d98a commit 15f5367

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

package-lock.json

+19-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"ethers": "^5.7.2",
7575
"siwe": "^2.0.5",
7676
"wagmi": "^0.10.3",
77-
"zod": "^3.20.2"
77+
"zod": "^3.20.2",
78+
"zod-validation-error": "^0.3.0"
7879
},
7980
"peerDependencies": {
8081
"express": ">=4",

src/api.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { IncomingMessage, ServerResponse } from 'http';
22
import { generateNonce, SiweMessage } from 'siwe';
3+
import { fromZodError } from 'zod-validation-error';
34
import { GetSessionResponse, signInRequestSchema, SignInResponse, SignOutResponse } from './types.js';
45

56
interface Request extends IncomingMessage {
@@ -38,7 +39,7 @@ export const signIn: RequestHandler<SignInResponse> = async (req, res) => {
3839
if (!nonce) return res.status(400).send("Bad Request");
3940

4041
const parsedBody = signInRequestSchema.safeParse(req.body);
41-
if (!parsedBody.success) return res.status(400).send("Bad Request");
42+
if (!parsedBody.success) return res.status(400).send(fromZodError(parsedBody.error).message);
4243
const { message, signature } = parsedBody.data;
4344

4445
const { success, error, data } = await new SiweMessage(message).verify({

0 commit comments

Comments
 (0)