diff --git a/constants/data.ts b/constants/data.ts index 23832fd2..b70d29f0 100644 --- a/constants/data.ts +++ b/constants/data.ts @@ -530,3 +530,5 @@ pub contract Example { } } `; + +export const jwt = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTcxNzg1OTU2NCwiZXhwIjoxNzE3ODYzMTY0fQ.WnYp2KahzKGxPTjIP9_IZsN48XVmaTKNTGF63gKoXhg`; diff --git a/package.json b/package.json index 11a62302..cc7c29ca 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,8 @@ "ts-to-zod": "^1.11.0", "typescript": "4.3.4", "xml-js": "^1.6.11", - "yaml": "^1.10.2" + "yaml": "^1.10.2", + "jsonwebtoken": "^8.5.1" }, "devDependencies": { "@types/lodash": "^4.14.170", diff --git a/pages/jwt-to-json.tsx b/pages/jwt-to-json.tsx new file mode 100644 index 00000000..39bea849 --- /dev/null +++ b/pages/jwt-to-json.tsx @@ -0,0 +1,28 @@ +import ConversionPanel from "@components/ConversionPanel"; +import * as React from "react"; +import { useCallback } from "react"; +import jwt from "jsonwebtoken"; + +export default function JwtToJson() { + const name = "jwt-to-json"; + + const transformer = useCallback(async ({ value }) => { + try { + const decoded = jwt.decode(value.trim(), { complete: true }); + return JSON.stringify(decoded, null, 2); + } catch (error) { + return `Error decoding JWT: ${error}`; + } + }, []); + + return ( + + ); +} diff --git a/utils/routes.tsx b/utils/routes.tsx index cb19f16f..6736ef13 100644 --- a/utils/routes.tsx +++ b/utils/routes.tsx @@ -222,7 +222,7 @@ export const categorizedRoutes = [ label: "to Typescript", path: "/js-object-to-typescript", desc: "An online REPL for converting JS Object to Typescript." - }, + } ] }, { @@ -393,6 +393,10 @@ export const categorizedRoutes = [ { label: "Cadence to Go", path: "/cadence-to-go" + }, + { + label: "JWT to JSON", + path: "/jwt-to-json" } ] }