mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
SPRINT-15: fixed unauthorized user bug
This commit is contained in:
@ -19,26 +19,36 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {Auth0Provider, useAuth0} from "@auth0/auth0-react";
|
||||||
import React, {useEffect} from "react";
|
import React, {useEffect} from "react";
|
||||||
import {useCookies} from "react-cookie";
|
import {useCookies} from "react-cookie";
|
||||||
import {SESSION_ID_COOKIE_NAME} from "App";
|
import {SESSION_ID_COOKIE_NAME} from "App";
|
||||||
|
import {AUTH0_CLIENT_ID, AUTH0_DOMAIN} from "index";
|
||||||
|
|
||||||
interface Props
|
interface Props
|
||||||
{
|
{
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function HandleAuthorizationError({errorMessage}: Props)
|
function HandleAuthorizationError({errorMessage}: Props)
|
||||||
{
|
{
|
||||||
|
|
||||||
const [, , removeCookie] = useCookies([SESSION_ID_COOKIE_NAME]);
|
const [, , removeCookie] = useCookies([SESSION_ID_COOKIE_NAME]);
|
||||||
|
const {logout} = useAuth0();
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
|
logout();
|
||||||
removeCookie(SESSION_ID_COOKIE_NAME, {path: "/"});
|
removeCookie(SESSION_ID_COOKIE_NAME, {path: "/"});
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>{errorMessage}</div>
|
<Auth0Provider domain={AUTH0_DOMAIN} clientId={AUTH0_CLIENT_ID}>
|
||||||
|
<div>
|
||||||
|
<div>{errorMessage}</div>
|
||||||
|
</div>
|
||||||
|
</Auth0Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ import {MaterialUIControllerProvider} from "context";
|
|||||||
import HandleAuthorizationError from "HandleAuthorizationError";
|
import HandleAuthorizationError from "HandleAuthorizationError";
|
||||||
import ProtectedRoute from "qqq/auth0/protected-route";
|
import ProtectedRoute from "qqq/auth0/protected-route";
|
||||||
|
|
||||||
const domain = process.env.REACT_APP_AUTH0_DOMAIN;
|
export const AUTH0_DOMAIN = process.env.REACT_APP_AUTH0_DOMAIN;
|
||||||
const clientId = process.env.REACT_APP_AUTH0_CLIENT_ID;
|
export const AUTH0_CLIENT_ID = process.env.REACT_APP_AUTH0_CLIENT_ID;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
function Auth0ProviderWithRedirectCallback({children, ...props})
|
function Auth0ProviderWithRedirectCallback({children, ...props})
|
||||||
@ -47,7 +47,9 @@ function Auth0ProviderWithRedirectCallback({children, ...props})
|
|||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
<HandleAuthorizationError errorMessage={searchParams.get("error_description")} />
|
<Auth0Provider {...props}>
|
||||||
|
<HandleAuthorizationError errorMessage={searchParams.get("error_description")} />
|
||||||
|
</Auth0Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -64,8 +66,8 @@ function Auth0ProviderWithRedirectCallback({children, ...props})
|
|||||||
render(
|
render(
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Auth0ProviderWithRedirectCallback
|
<Auth0ProviderWithRedirectCallback
|
||||||
domain={domain}
|
domain={AUTH0_DOMAIN}
|
||||||
clientId={clientId}
|
clientId={AUTH0_CLIENT_ID}
|
||||||
redirectUri={`${window.location.origin}/dashboards/overview`}
|
redirectUri={`${window.location.origin}/dashboards/overview`}
|
||||||
>
|
>
|
||||||
<MaterialUIControllerProvider>
|
<MaterialUIControllerProvider>
|
||||||
|
Reference in New Issue
Block a user