Search code examples
node.jsreactjspostgresqlrestify

how use restify to connect postgreSQL to reactjs frontend?


Login.js This is login page designed in Reactjs and requirement is goto next page after next page after successful authentication, But database is created using postgreSQL and table name is 'user' which stores username and password. And development requirements are:

  • frontend :reactjs
  • backend : restify(nodejs)
  • Database : postgreSQL So I want to know how i can connect postgreSQL table to this login page and how authenticate user?
    class Login extends Component {
        render() {
            return (
                <div>
                <div >
                <div >
                    <h1 >Login</h1>
                <div >
                    <input type="text" placeholder="Username"/>
                </div>
                <div>
                    <input type="password" placeholder="Password"/>
                </div>
                    <button type="submit">Log in</button>
              
                </div>
                </div>
                </div>
            )
        }
    }
    
    export default Login

Solution

  • It seems you are a beginner with the concepts,

    You must try to check some tutorials and then start.

    Coming back to your question I will try to answer as simple I can,

    1. Frontend (react in your example) will need to consume some API (login API of your backend).
    2. Your backend will be created in nodejs using restify (As per your example), this piece of code will integrate with a database which is postgress (as per your example).
    3. this backend will receive the request body from say Frontend and validate in the database and give respectively user found or not found response.
    4. If the user found a response your frontend will route to the next page or in case not found frontend will show error message respectively.

    Hope you got the idea,

    Caveat:- there will so many concepts like hashing, token, cookie, local storage, etc that will come in the journey.