-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth0-provider.tsx
More file actions
44 lines (37 loc) · 1.24 KB
/
Copy pathauth0-provider.tsx
File metadata and controls
44 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React from 'react';
import { Auth0Provider } from '@auth0/auth0-react';
import { useNavigate } from 'react-router-dom';
interface Auth0ProviderWithNavigateProps {
children: React.ReactNode;
}
export const Auth0ProviderWithNavigate: React.FC<Auth0ProviderWithNavigateProps> = ({ children }) => {
const navigate = useNavigate();
const domain = import.meta.env.VITE_AUTH0_DOMAIN;
const clientId = import.meta.env.VITE_AUTH0_CLIENT_ID;
const audience = import.meta.env.VITE_AUTH0_AUDIENCE;
// For BrowserRouter, use the origin directly
const redirectUri = window.location.origin;
const onRedirectCallback = (appState?: any) => {
console.log('Auth0 redirect callback', { appState });
navigate(appState?.returnTo || '/');
};
if (!domain || !clientId || !audience) {
return <div>Missing Auth0 configuration. Please check your .env.local file.</div>;
}
return (
<Auth0Provider
domain={domain}
clientId={clientId}
authorizationParams={{
redirect_uri: redirectUri,
audience: audience,
scope: 'openid profile email',
}}
onRedirectCallback={onRedirectCallback}
useRefreshTokens={true}
cacheLocation="localstorage"
>
{children}
</Auth0Provider>
);
};