https://github.com/itzdiv/auth
This application uses Express.js with Passport.js for authentication, integrating local and Google OAuth strategies. It securely manages user sessions, encrypts passwords with bcrypt, and stores credentials in a PostgreSQL database.
https://github.com/itzdiv/auth
Last synced: about 1 year ago
JSON representation
This application uses Express.js with Passport.js for authentication, integrating local and Google OAuth strategies. It securely manages user sessions, encrypts passwords with bcrypt, and stores credentials in a PostgreSQL database.
- Host: GitHub
- URL: https://github.com/itzdiv/auth
- Owner: itzdiv
- Created: 2025-01-29T18:08:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-29T18:15:23.000Z (over 1 year ago)
- Last Synced: 2025-02-07T13:41:30.822Z (over 1 year ago)
- Language: EJS
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Authentication System Overview
This Express.js application implements user authentication using Passport.js, bcrypt for password hashing, PostgreSQL as the database, and Google OAuth for third-party authentication.
Key Features:
-
Session Management: Usesexpress-sessionto handle user sessions securely. -
Local Authentication: Implements username-password authentication using Passport Local Strategy and bcrypt for secure password storage. -
Google Authentication: Enables users to log in via Google OAuth2. -
Database Integration: Stores user credentials in PostgreSQL, ensuring persistent authentication.
Authentication Flow
Registration
When a user registers, the password is hashed using bcrypt and stored in the database.
INSERT INTO users (email, password) VALUES ($1, $2)
Login
During login, the provided password is compared with the stored hashed password using bcrypt.
Google OAuth Login
Google authentication is handled via Passport's Google OAuth2 strategy. If the user is new, their email is stored in the database.
Session Handling
Users' authentication states are maintained using Passport's serialization and deserialization methods.
Routes Overview
-
GET /: Home page -
GET /login: Login page -
GET /register: Registration page -
POST /register: Handles user registration -
POST /login: Handles user login -
GET /secrets: Protected route requiring authentication -
GET /logout: Logs out the user -
GET /auth/google: Redirects users to Google OAuth