Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successful Login but its not Redirecting #16

Open
jansoriano-dev opened this issue Oct 12, 2019 · 3 comments
Open

Successful Login but its not Redirecting #16

jansoriano-dev opened this issue Oct 12, 2019 · 3 comments

Comments

@jansoriano-dev
Copy link

Hi, I'm already at the part 7 of the video tutorial, and I was able to Login but it's not redirecting to the dashboard.

import React, { Component } from 'react';
import { Link, Redirect } from "react-router-dom";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import { login } from "../../actions/auth";

export class Login extends Component {
state = {
username:"",
password:""
};

static propTypes = {
    login: PropTypes.func.isRequired,
    isAutheticated: PropTypes.bool
};

onSubmit = e => {
    e.preventDefault();
    this.props.login(this.state.username, this.state.password);
};

onChange = e => this.setState({ [e.target.name]: e.target.value });

render() {
    if(this.props.isAutheticated) {
        return <Redirect to="/" />;
    }
    const { username, password } = this.state;
    return (
        <div className ="col-md-6-m-auto">
            <div className="card card-body mt-5">
                <h2 className="text-center">Login</h2>
                <form onSubmit={this.onSubmit}>
                    <div className="form-group">
                        <label>Username</label>
                        <input type="text" className="form-control"
                        name="username"
                        onChange={this.onChange}
                        value={username} />
                    </div>
                    <div className="form-group">
                        <label>Password</label>
                        <input type="password" className="form-control"
                        name="password"
                        onChange={this.onChange}
                        value={password} />
                    </div>
                    <div className="form-group">
                        <button type="submit" className="btn btn-primary">Login</button>
                    </div>
                    <p>
                        Don't have an account? <Link to="/register">Register</Link>
                    </p>
                </form>
            </div>
        </div>
    );
}

}

const mapStateToProps = state => ({
isAutheticated: state.auth.isAutheticated
});

export default connect(mapStateToProps, { login })(Login);
Capture2

@jansoriano-dev jansoriano-dev changed the title not Redirecting after Login Successful Login but its not Redirecting Oct 12, 2019
@cpinamtz
Copy link

cpinamtz commented Jul 1, 2020

As I suggested in the issue #13, please check how you've spelt the auth.isAuthenticated variable inside the PrivateRoute.js. Ensure that all the React code use the same naming. Otherwise, it will happen that, a constant back and forth between / and /login paths.

@jansoriano-dev
Copy link
Author

jansoriano-dev commented Jul 2, 2020 via email

@TomNewton1
Copy link

I am not being redirected after successfully logging in. It doesn't seem like the following code is actually rendering again once the user has logged in:

if (this.props.isAuthenticated) {
return
}

I have console logged it and this bit of code doesn't actually get called after the user has logged in. Is anyone else having this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants