When I trying to call jwt to authenticate via auth0, it throws an error: “Service not found: http://localhost:8000”.
import React, { useContext, useEffect } from 'react'
import Header from '../Header/Header'
import Footer from '../Footer/Footer'
import { Outlet } from "react-router-dom"
import { useAuth0 } from "@auth0/auth0-react"
import UserDetailContext from '../../context/UserDetailContext'
import { useMutation } from "react-query";
import { createUser } from '../../utils/api.js'
const Layout = () => {
const { isAuthenticated, user, getAccessTokenWithPopup } = useAuth0()
const { setUserDetails } = useContext(UserDetailContext)
const { mutate } = useMutation({
mutationKey: [user?.email],
mutationFn: (token) => createUser(user?.email, token)
});
useEffect(() => {
const getTokenAndRegister = async () => {
const res = await getAccessTokenWithPopup({
authorizationParams: {
audience: "http://localhost:8000",
scope: "openid profile email"
}
})
localStorage.setItem("access_token", res)
setUserDetails((prev) => ({ ...prev, token: res }));
console.log(res)
}
isAuthenticated && getTokenAndRegister()
}, [isAuthenticated]);
return (
<>
<div style={{ background: "var(--black)", overflow: "hidden" }}>
<Header />
<Outlet />
</div>
<Footer />
</>
)
}
export default Layout
auth0Config.js
import {auth} from 'express-oauth2-jwt-bearer'
const jwtCheck = auth({
audience: "http://localhost:8000",
issuerBaseURL: "my url)",
tokenSigningAlg: "RS256"
})
export default jwtCheck
main.jsx
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="my domain)"
clientId="rmy id)"
authorizationParams={{
redirect_uri: "http://localhost:5173"
}}
audience="http://localhost:8000"
scope="openid profile email"
>
<App />
</Auth0Provider>
</React.StrictMode>
);
I tried to rewrite the code from scratch but no luck. Also updated all dependencies to the latest versions, the error persists. Instead of a token, I get a service not found.