This example Express application uses Passport for authentication. Two common strategies are implemented:
passport-local: Username-and-password authentication using credentials stored in the application's database.passport-google-oauth20: OAuth social login using Google.
- Node.js 22.0.0 or higher
- npm 10.0.0 or higher
Clone the repository.
git clone https://github.com/fusionauth/fusionauth-example-migrating-node.git webApp
cd webAppInstall dependencies.
npm installSet up environment variables.
cp config.env.example .envUpdate .env with the following configuration.
# Server Configuration
PORT=3000
NODE_ENV=development
# Session Configuration
SESSION_SECRET=your-super-secret-session-key-change-this-in-production
# Google OAuth Configuration
# Get these from https://console.developers.google.com/
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secretSet up the database and seed test users.
npm run setup(Optional) Start FusionAuth for migration testing.
npm run fusionauth:upFusionAuth will be available at http://localhost:9011.
npm run devnpm startThe application will be available at http://localhost:3000.
- Go to Google Cloud Console.
- Create a new project or select an existing one.
- Enable the Google+ API.
- Go to "Credentials" and create an OAuth 2.0 Client ID.
- Add
http://localhost:3000/auth/google/callbackto the authorized redirect URIs. - Copy the Client ID and Client Secret to your
.envfile.
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT UNIQUE NOT NULL,
password TEXT,
name TEXT,
google_id TEXT UNIQUE,
avatar TEXT,
provider TEXT DEFAULT 'local',
verified BOOLEAN DEFAULT 0,
active BOOLEAN DEFAULT 1,
last_login_at DATETIME,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);CREATE TABLE sessions (
session_id TEXT PRIMARY KEY,
expires INTEGER NOT NULL,
data TEXT
);GET /login: Login pagePOST /login: Local authenticationGET /register: Registration pagePOST /register: User registrationGET /logout: LogoutGET /auth/google: Google OAuth loginGET /auth/google/callback: Google OAuth callback
GET /profile: User profile pagePOST /profile: Update profileGET /dashboard: Dashboard overviewGET /users: User managementPOST /users/:id/delete: Delete userPOST /users/:id/toggle-active: Toggle user status
This project includes a pre-configured FusionAuth instance for testing migrations.
# Start FusionAuth with PostgreSQL and MailCatcher
npm run fusionauth:up
# View FusionAuth logs
npm run fusionauth:logs
# Stop FusionAuth
npm run fusionauth:down- Client Secret:
super-secret-secret-that-should-be-regenerated-for-production - Redirect URL:
http://localhost:3000/auth/fusionauth/callback