Answer the question
In order to leave comments, you need to log in
How to redirect user after authentication?
Hello. Tell me how you can redirect the user after authentication to the page that he wanted.
App.jsx
<Route path='/movies/new' element={<AuthWare component={NewMovieForm} />} />
const AuthWare = ({ component: Component }) => {
if (!authService.getCurrentUser()) return <Navigate to='/login' />
return <Component/>;
}
doSumbit = async () => {
try {
const { data } = this.state;
await auth.login(data.username, data.password);
window.location.href = '/';
} catch (ex) {
if (ex.response && ex.response.status === 400) {
const errors = {...this.state.errors};
errors.username = ex.response.data;
this.setState({ errors });
}
}
}
Answer the question
In order to leave comments, you need to log in
Add the backUrl parameter to the login form call, in the form redirect the user to this address if it is defined
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question