I use the library
"@auth0/auth0-react": "^2.2.1"
I connect with the function loginWithPopup from the Auth0 hook: I can connect, but after refreshing the page I don’t receive a token with getAccessTokenSilently and need to connect again.
We use Cross-Origin Authentication.
This happens in browsers like Safari, Firefox, Brave.
My code:
import {useAuth0} from "@auth0/auth0-react";
const HomePage: FC = () => {
const {loginWithPopup} = useAuth0();
return (
<Button onClick={() => loginWithPopup()}>{'Login'}</Button>
)
}
also I don’t get user details: only user_id (sub)
const { user } = useAuth0();
console.log(user) //{sub: 'google-oauth2|111490016442351871588'}
Also, I try to log in with API of Auth0.
As for the API, I’m using a library
"auth0-js": "^9.22.1"
In the same browsers I try to connect using functions like
import auth0 from "auth0-js";
export const webAuth = new auth0.WebAuth({
domain: process.env.REACT_APP_AUTH0_DOMAIN as string,
clientID: process.env.REACT_APP_AUTH0_CLIENT_ID as string,
audience: process.env.REACT_APP_AUTH0_AUDIENCE as string,
redirectUri: window?.location?.origin,
responseType: 'token',
scope: 'openid profile email read:current_user update:current_user_metadata offline_access',
});
const loginWithUsernamePassword = useCallback((data: TFormData) => {
return new Promise((resolve, reject) => {
webAuth.login({
connection: DATABASE_CONNECTION,
username: data.username,
password: data.password,
realm: DATABASE_CONNECTION,
state: stateParam,
} as CrossOriginLoginOptions, (error, result) => {
if (error) {
console.log(error)
reject(error);
setErrorResponse(error.error_description || error.description || 'something went wrong')
return;
}
resolve(result);
})
})
}, [webAuth]);
const loginWithGoogle = useCallback(() => {
webAuth.authorize({connection: 'google-oauth2', redirectUri});
}, [webAuth]);
and the connection doesn’t happen at all in both cases
What do I do wrong?