I have this task in our React project that needs to encrypt the object inside a state using jwt. It throws an error that says "Cannot read property '2' of null" while I use the .sign() method and including the RS256 algorithm.
Here is a sample of what I am doing .
import { useState } from "react";
import "./styles.css";
import jwt from "jsonwebtoken";
import configData from "./conf.json";
export default function App() {
const [state] = useState({
name: "John",
age: 22,
sex: "Male"
});
const stateHashed = jwt.sign(state, configData.SECRET_KEY, {
algorithm: "RS256"
});
console.log(configData.SECRET_KEY);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<h1>Hashed key</h1>
<h3>{stateHashed}</h3>
</div>
);
}
Here is the conf.json file for the secret key
{
"SECRET_KEY": "exDj"
}
Thanks for anyone who can help.