This app illustrates how to use Passport with Express to sign users in with a username and password. Use this example as a starting point for your own web applications.
To run this app, clone the repository and install dependencies:
$ git clone https://github.com/passport/todos-express-password-flash.git
$ cd todos-express-password-flash
$ npm install
Then start the server.
$ npm start
Navigate to http://localhost:3000
.
Follow along with the step-by-step Username & Password Tutorial to learn how this app was built.
This example illustrates how to use Passport and the passport-local
strategy within an Express application to sign users in with a username and
password.
This app implements the features of a typical TodoMVC app, and adds sign in functionality. This app is a traditional web application, in which all application logic and data persistence is handled on the server.
User interaction is performed via HTML pages and forms, which are rendered via EJS templates and styled with vanilla CSS. Data is stored in and queried from a SQLite database.
After users sign in, a login session is established and maintained between the server and the browser with a cookie. As authenticated users interact with the app, creating and editing todo items, the login state is restored by authenticating the session.
When sign in fails, an informative message is displayed to users using the
failureFlash
option, in conjuction with connect-flash
middleware.
Created by Jared Hanson