Error:
PS C:\Users\91955\Desktop\Full-stack-real-estate-youtube\server> node index.js
Server is running on port 8000
InvalidTokenError: Invalid Compact JWS
at C:\Users\91955\Desktop\Full-stack-real-estate-youtube\server\node_modules\express-oauth2-jwt-bearer\dist\index.js:300:19
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:\Users\91955\Desktop\Full-stack-real-estate-youtube\server\node_modules\express-oauth2-jwt-bearer\dist\index.js:403:24
import { auth } from "express-oauth2-jwt-bearer";
const jwtCheck = auth({
audience: "http://localhost:8000",
issuerBaseURL: "https:XXXXXXXXXXXXXX.us.auth0.com",
tokenSigningAlg: "RS256",
});
export default jwtCheck;
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import { Auth0Provider } from "@auth0/auth0-react";
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<Auth0Provider
domain="XXXXXXXl.us.auth0.com"
clientId="XXXXXXXXXXXXXXDdp"
authorizationParams={{
redirect_uri: "http://localhost:5173",
}}
audience="http://localhost:8000"
scope="openid profile email"
>
<App />
</Auth0Provider>
</React.StrictMode>
);
Auth0 dashboard
So the problem is occurring here in all the POST
requests. Whenever I try to POST
something, it throws InvalidTokenError: Invalid Compact JWS
.
Api.js file :
import axios from "axios";
import dayjs from "dayjs";
import { toast } from "react-toastify";
export const api = axios.create({
baseURL: "http://localhost:8000/api",
});
export const getAllProperties = async () => {
try {
const response = await api.get("/residency/allresd", {
timeout: 10 * 1000,
});
if (response.status === 400 || response.status === 500) {
throw response.data;
}
return response.data;
} catch (error) {
toast.error("Something went wrong");
throw error;
}
};
export const getProperty = async (id) => {
try {
const response = await api.get(`/residency/${id}`, {
timeout: 10 * 1000,
});
if (response.status === 400 || response.status === 500) {
throw response.data;
}
return response.data;
} catch (error) {
toast.error("Something went wrong");
throw error;
}
};
export const createUser = async (email, token) => {
try {
await api.post(
`/user/register`,
{ email },
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
} catch (error) {
toast.error("Something went wrong, Please try again");
throw error;
}
};
export const bookVisit = async (date, propertyId, email, token) => {
try {
await api.post(
`/user/bookVisit/${propertyId}`,
{
email,
id: propertyId,
date: dayjs(date).format("DD/MM/YYYY"),
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
} catch (error) {
toast.error("Something went wrong, Please try again");
throw error;
}
};
export const removeBooking = async (id, email, token) => {
try {
await api.post(
`/user/removeBooking/${id}`,
{
email,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
} catch (error) {
toast.error("Something went wrong, Please try again");
throw error;
}
};
export const toFav = async (id, email, token) => {
try {
await api.post(
`/user/toFav/${id}`,
{
email,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
} catch (e) {
throw e;
}
};
export const getAllFav = async (email, token) => {
if (!token) return;
try {
const res = await api.post(
`/user/allFav`,
{
email,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return res.data["favResidenciesID"];
} catch (e) {
toast.error("Something went wrong while fetching favs");
throw e;
}
};
export const getAllBookings = async (email, token) => {
if (!token) return;
try {
const res = await api.post(
`/user/allBookings`,
{
email,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return res.data["bookedVisits"];
} catch (error) {
toast.error("Something went wrong while fetching bookings");
throw error;
}
};
export const createResidency = async (data, token) => {
console.log(data);
try {
const res = await api.post(
`/residency/create`,
{
data,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
} catch (error) {
throw error;
}
};
I tried this:
redirect_uri: window.location.origin,