We have an ReactJS App, and want to validate saved JWT Token at API end. For that adding await axiosClient.post("${URL}/AuthenticateUser/ValidateToken") in App.tsx, it's throwing an error.
index.tsx:
const msalInstance = new PublicClientApplication(msalConfig);
const container = document.getElementById('root');
const root = createRoot(container!);
root.render(
<MsalProvider instance={msalInstance}>
<App />
</MsalProvider>,
);
module.hot?.accept();
App.tsx:
async function App() {
let isAuthenticated = false;
const url = `${URL}/AuthenticateUser/ValidateToken`;
if (localStorage.getItem('token')) {
await axiosClient.post(url).then((result) => {
/* Do Something */
});
}
axiosClient.tsx:
export const axiosClient = axios.create({
baseURL: URL,
timeout: 300000,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${getToken()}`,
},
});
Error:
TS2786: 'App' cannot be used as a JSX component.
Its return type 'Promise<Element>' is not a valid JSX element.