Comments (4)
Hello,
You should be able to set appState.target when calling loginWithRedirect or using withAuthenticationRequired, that is what's used to redirect back to a specific route after handeling the callback.
Let me know if that doesnt help.
from auth0-react-samples.
Hello,
You should be able to set appState.target when calling loginWithRedirect or using withAuthenticationRequired, that is what's used to redirect back to a specific route after handeling the callback.
Let me know if that doesnt help.
Thanks for the quick response! Still encountering the issue of being redirected to the home url. I have made sure to add all necessary callback urls in the application settings.
// client/src/main.jsx
import { Auth0Provider } from '@auth0/auth0-react';
import { auth0_domain, auth0_client_id, auth0_audience } from '../config';
ReactDOM.createRoot(document.getElementById('root')).render(
<BrowserRouter>
<Auth0Provider
domain={auth0_domain}
clientId={auth0_client_id}
authorizationParams={{
redirect_uri: window.location.origin,
}}
// audience={auth0_audience}
>
<App />
</Auth0Provider>
</BrowserRouter>
);
// client/src/components/LoginButton.jsx
import React, { useContext } from 'react';
import { useAuth0 } from '@auth0/auth0-react';
import { AppContext } from '../contexts/AppContext';
const LoginButton = () => {
const { loginWithRedirect } = useAuth0();
const { isAuthenticated } = useContext(AppContext);
const targetPath = window.location.href;
const handleClick = () => {
console.log(window.location.href);
setTimeout(() => {
loginWithRedirect({ appState: { returnTo: window.location.targetPath } });
}, 2000); // delay the redirect by 2 seconds so we can log the path (2000 milliseconds)
};
return (
!isAuthenticated && (
<button onClick={handleClick}>
Log In
</button>
)
);
};
export default LoginButton;
Does the redirectUri specified in the Auth0Provider take precedence over uri specified in the appState.returnTo in the loginWithRedirect function? Really appreciate your help with this issue!
from auth0-react-samples.
You need appState.target, not appState.returnTo.
Would that work ?
from auth0-react-samples.
You need appState.target, not appState.returnTo.
Would that work ?
That didn't work. What did work however was changing the redirect_uri in the Auth0Provider to window.location.href. Thanks for your help!
from auth0-react-samples.
Related Issues (20)
- way too many deprecated libraries HOT 9
- `Failed to load resource: the server responded with a status of 400 ()` error with /authorize call - misconfiguration issue HOT 7
- Handle 403 Insufficient Scope errors in UI HOT 1
- Google account picture request forbidden HOT 3
- just a spinning circle HOT 3
- How to configure multiple App Client IDs in auth_config.json file? HOT 1
- Example for User Initiated Account Linking using this library HOT 2
- How to send Organization ID to Auth0Provider? HOT 1
- failed to load resource the server responded with a status of 400 () in React Node HOT 1
- #15 5.788 Cannot find file './auth_config.json' in './src'. Error HOT 1
- Cypress and auth0-react integration not working HOT 3
- Oops... Unauthorized HOT 4
- Do I need to call getAccessTokenSilently every time I make an external API call? HOT 2
- Adjust your current browser settings from 'Strict' to 'Moderate'. HOT 2
- Request failed with status code 404 HOT 1
- Chrome - Invalid state HOT 2
- Firefox - Session lost on refresh and SSO does not work HOT 3
- Auth0-react failing silently on succesful login HOT 4
- isAuthenticated is null in auth0-react HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auth0-react-samples.