I have spent the past week trying to find a solution for this in this forum and SO and can’t find one. I am getting the Login required error when I try to use the getAccessTokenSilently in my Vite SPA. The page that I am trying to access it on:
useMemo(() => {
(async () => {
try {
const token = await getAccessTokenSilently({
authorizationParams: {
audience: `https://${import.meta.env.VITE_AUTH_DOMAIN}/api/v2/`,
scope: 'read:current_user'
}
})
axios.post(import.meta.env.VITE_BAM_API, {
authentication: `Bearer ${token}`,
})
.then(res => console.log(res))
.catch(e => console.error(e))
} catch (e) {
console.error(e)
}
})()
}, [getAccessTokenSilently])
My AuthProvider setup:
const providerConfig = {
domain: config.domain,
clientId: config.clientId,
cacheLocation: 'localstorage',
useRefreshToken: true,
authorizationParams: {
redirect_uri: (typeof window !== 'undefined' && window.location.origin) || 'not-authenticated',
...(config.audience ? {audience: config.audience} : null)
}
}
return (
<BrowserRouter>
<AuthProvider
{...providerConfig}
>
<div className="App">
<header className="App-header">
<h1>Welcome to BAM!</h1>
</header>
<main>
<Routes>
<Route path='/admin/dashboard' element={<AdminDashboard />} />
<Route path='/login' element={<Login/>} />
<Route path='/logout' element={<Logout/>} />
<Route path='/:folder' element={<UploadForm/>} />
<Route path='/' index={true} element={<Home/>} />
</Routes>
</main>
</div>
</AuthProvider>
</BrowserRouter>
);
}
domains are identical at this point I don’t know what or how I am supposed to use this. None of the other posts don’t point to a definitive way of using this. What am I doing wrong???