-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetSignature.ts
39 lines (36 loc) · 1.11 KB
/
getSignature.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { type NextApiRequest, type NextApiResponse } from "next";
import axios from "axios";
import { type Error } from "@/types";
interface Response extends NextApiResponse {
status(code: number): Response;
send(data: { message: string; nonce: string } | Error): void;
}
export default async function handler(_req: NextApiRequest, res: Response) {
try {
const messageAndNonce = await fetchMessageAndNonce();
if (messageAndNonce) {
res.status(200).send(messageAndNonce);
} else {
res.status(500).send({ error: "Internal Server Error" });
}
} catch (error) {
console.error(error);
res.status(500).send({ error: "Internal Server Error" });
}
}
const fetchMessageAndNonce = async () => {
const axiosSigningMessageConfig = {
headers: {
"X-API-KEY": process.env.GITCOIN_API_KEY!,
Accept: "application/json",
"Content-Type": "application/json",
},
};
const { data } = await axios.get<
{ message: string; nonce: string } | undefined
>(
"https://api.scorer.gitcoin.co/registry/signing-message",
axiosSigningMessageConfig,
);
return data;
};