Ad

Converting An Existing ASP.Net User Identity Application To Use ReactJs

I have an existing website which uses MVC ASP.Net identity with lots of users.

I would really like to rebuild the application using React, I have a sample .NetCore React application as produced with visual studio 2017 and I was hoping I could port over the membership somehow so I can integrate it into my application.

I have tried copying over the MVC accounts controller to try and call the account login method directly using AJAX but it is giving me a 500 error.

Is it possible to do this, and if so has anyone got any ideas on how to do it or any examples, I have searched everywhere and cannot see anyone doing this?

My React component submit method looks like this, I am just trying to hit the action and do the usual authentication methods but it is not even getting there.

submit() {
    const details = { Email: this.state.userName, Password: this.state.password, RememberMe: false };

    $.ajax({
        url: '/Account/Login',
        type: 'POST',
        data: {
            model: details,
            returnUrl: null
        },
        success: function (result) {
            alert(result);
        },
        error: function (errorResult) {
            alert("FAIL");
        }
    });
}
Ad

Answer

For anyone interested, I have been able to achieve what I want to by following the example here using JWT tokens.

https://medium.com/@ozgurgul/asp-net-core-2-0-webapi-jwt-authentication-with-identity-mysql-3698eeba6ff8

Ad
source: stackoverflow.com
Ad