2

After getting user email and password and getting access to enter, app goes to user profile page and goes after that to sign in form again. That happened when I added .then(data => ...). One more issue is that I'm using POST method but after signing in at first time I can see email and password in URL and it stays there after going to sign in form again. And again if I remove .then(data => ...) everything works fine with POST method.

onSubmitSignIn = () => {
        fetch('http://localhost:3000/signin', {
            method: 'post',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify({
            email: this.state.signInEmail,
            password: this.state.signInPassword 
            })
        })
        .then(response => response.json())
        .then(data => {
               if (data === 'success') {
                   this.props.onRouteChange('home');
               }
        });
    };

This function is for Sign In button. .onRouteChange('home') just shows what components should app show.

3
  • how do you trigger you onSubmitSignIn function ? Commented Apr 22, 2019 at 7:11
  • <input type="submit" onClick={this.onSubmitSignIn} value="Sign in"/> Commented Apr 22, 2019 at 7:17
  • where onRouteChange function is coming from? is it your function or a library function? if it yours - what is it doing? Commented Apr 22, 2019 at 8:02

2 Answers 2

3

You didn't provide the whole thing but one thing I can help with the submit is to stop the default behavior of the form:

onSubmitSignIn = (event) => {
  // ...
  event.preventDefault();
}

Try this first then go figure other things later.

Sign up to request clarification or add additional context in comments.

1 Comment

It helped. Thank you so much! But why did it help?
0

Just adding what was happening in my case (especially since probably not many would think of searching with 'dotnet' in their question)

If the backend being used is DotNet, and in Visual Studio, you may see "aspnetcore-browser-refresh" script logging in devtools console. Regardless you can check if its active in your project and disable it:

  1. Go to Tools > Options > Projects and Solutions > ASP.NET Core
  2. Disable CSS Hot Reload
  3. For Auto build and refresh, ensure the selected option is not Refresh browser after build or Auto build and refresh browser after build
  4. Go to the Standard Toolbar > Browser Link.
  5. Uncheck Enable Browser Link and Enable CSS Hot Reload

Apparently, this was not an app-refresh instead a whole page reload and only happened when a button press leads to an api call having a response.

Source: https://developercommunity.visualstudio.com/t/No-way-to-stop-aspnetcore-browser-refres/10376962

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.