-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Fix provider order using react router 9
Due to changes in react router 9, some of the providers needed to be moved to the root layout.
- Loading branch information
Showing
5 changed files
with
71 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Auth0Provider, type AppState } from "@auth0/auth0-react"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
type AuthProviderWithNavigateProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const AuthProviderWithNavigate: React.FC<AuthProviderWithNavigateProps> = ({ children }) => { | ||
const navigate = useNavigate(); | ||
|
||
const domain = (import.meta.env.VITE_APP_AUTH0_DOMAIN as string) || ""; | ||
const clientId = (import.meta.env.VITE_APP_AUTH0_CLIENT_ID as string) || ""; | ||
|
||
const onRedirectCallback = (appState?: AppState) => { | ||
navigate(appState?.returnTo || window.location.pathname); | ||
}; | ||
|
||
return ( | ||
<Auth0Provider | ||
domain={domain} | ||
clientId={clientId} | ||
authorizationParams={{ | ||
audience: "https://api.kdvmanager.nl/", | ||
redirect_uri: window.location.origin, | ||
}} | ||
onRedirectCallback={onRedirectCallback} | ||
> | ||
{children} | ||
</Auth0Provider> | ||
); | ||
}; | ||
|
||
export default AuthProviderWithNavigate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import AuthProviderWithNavigate from "./AuthProviderWithNavigate"; | ||
import MainNavbar from "./MainNavbar"; | ||
import { Outlet } from "react-router-dom"; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
function AuthProviderLayout() { | ||
return ( | ||
<AuthProviderWithNavigate> | ||
<QueryClientProvider client={queryClient}> | ||
<MainNavbar> | ||
<Outlet /> | ||
</MainNavbar> | ||
</QueryClientProvider> | ||
</AuthProviderWithNavigate> | ||
); | ||
} | ||
|
||
export default AuthProviderLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters