-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth0-provider.tsx
More file actions
46 lines (39 loc) · 1.28 KB
/
Copy pathauth0-provider.tsx
File metadata and controls
46 lines (39 loc) · 1.28 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
45
46
import React from 'react';
import { Auth0Provider } from '@auth0/auth0-react';
import { useNavigate } from 'react-router-dom';
import { useI18n } from './contexts/I18nContext';
interface Auth0ProviderWithNavigateProps {
children: React.ReactNode;
}
export const Auth0ProviderWithNavigate: React.FC<Auth0ProviderWithNavigateProps> = ({ children }) => {
const navigate = useNavigate();
const { t } = useI18n();
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>{t('missingAuth0Config')}</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>
);
};