
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
simple-express-react-auth
Advanced tools
A lightweight authentication package for Express/React apps with single password protection using cookie-session
A lightweight authentication package for Express/React applications that provides single-password protection with session management.
npm install simple-express-react-auth
const express = require('express');
const cookieSession = require('cookie-session');
const { expressAuth } = require('simple-express-react-auth');
const app = express();
// Session middleware (required)
app.use(cookieSession({
name: 'session',
keys: ['your-secret-key'], // Use multiple keys for key rotation
maxAge: 24 * 60 * 60 * 1000 // 24 hours
}));
app.use(express.json());
// Create auth system
const { router, requireAuth } = expressAuth.createAuth({
password: 'your-secret-password'
});
// Add auth routes
app.use('/auth', router);
// Protect your routes
app.get('/protected', requireAuth, (req, res) => {
res.json({ message: 'This is protected!' });
});
app.listen(3000);
import React from 'react';
import { AuthProvider, ProtectedRoute, LogoutButton } from 'simple-express-react-auth/react';
function App() {
return (
<AuthProvider apiBaseUrl="http://localhost:3000">
<div>
<h1>My Protected App</h1>
<ProtectedRoute>
<div>
<p>Welcome! You are authenticated.</p>
<LogoutButton />
</div>
</ProtectedRoute>
</div>
</AuthProvider>
);
}
export default App;
createAuth(options)Creates authentication router and middleware.
Options:
password (string) - Plain text password to hash and use for authhashedPassword (string) - Pre-hashed password (alternative to password)loginPath (string) - Login endpoint path relative to router mount (default: /login)logoutPath (string) - Logout endpoint path relative to router mount (default: /logout)statusPath (string) - Status endpoint path relative to router mount (default: /status)saltRounds (number) - BCrypt salt rounds (default: 12)Returns:
router - Express router with auth endpointsrequireAuth - Middleware for API route protectionrequireAuthRedirect - Middleware for HTML route protection with redirectPOST /auth/login - Login with passwordGET /auth/logout - Logout and clear sessionGET /auth/status - Check authentication statusAuthProviderContext provider for authentication state.
Props:
apiBaseUrl (string) - Base URL for auth API calls (default: '')statusPath (string) - Status endpoint path (default: '/auth/status')loginPath (string) - Login endpoint path (default: '/auth/login')logoutPath (string) - Logout endpoint path (default: '/auth/logout')useAuth()Hook to access authentication state and methods.
Returns:
isAuthenticated (boolean) - Current auth statusisLoading (boolean) - Loading stateerror (string|null) - Current error messagelogin(password) - Login functionlogout() - Logout functioncheckAuthStatus() - Refresh auth statusProtectedRouteComponent that conditionally renders children based on auth status.
Props:
children - Content to render when authenticatedfallback - Custom component to render when not authenticatedloadingComponent - Custom loading componentclassName - CSS class nameLoginFormReady-to-use login form component.
Props:
onLoginSuccess - Callback function on successful loginclassName - CSS class namesubmitButtonText - Button text (default: 'Login')passwordPlaceholder - Input placeholder (default: 'Enter password')showError - Show error messages (default: true)LogoutButtonButton component for logging out.
Props:
children - Button content (default: 'Logout')onLogoutSuccess - Callback function on successful logoutclassName - CSS class nameimport { LoginForm } from 'simple-express-react-auth/react';
function CustomLogin() {
return (
<div className="my-login-container">
<LoginForm
className="my-login-form"
submitButtonText="Sign In"
passwordPlaceholder="Enter your password"
onLoginSuccess={() => console.log('Logged in!')}
/>
</div>
);
}
const { requireAuthRedirect } = expressAuth.createAuth({
password: 'secret'
});
// Redirect to custom login page
app.get('/admin', requireAuthRedirect('/custom-login'), (req, res) => {
res.send('Admin panel');
});
const bcrypt = require('bcrypt');
async function setupAuth() {
const hashedPassword = await bcrypt.hash('my-password', 12); // Updated to use higher salt rounds
const { router, requireAuth } = expressAuth.createAuth({
hashedPassword: hashedPassword
});
return { router, requireAuth };
}
function CustomProtectedRoute({ children }) {
return (
<ProtectedRoute
fallback={
<div className="custom-login">
<h2>Access Restricted</h2>
<LoginForm submitButtonText="Access System" />
</div>
}
>
{children}
</ProtectedRoute>
);
}
cookie-session for stateless sessions - no server-side storage requiredISC
Contributions welcome! Please read the contributing guidelines and submit pull requests to the main repository.
FAQs
A lightweight authentication package for Express/React apps with single password protection using cookie-session
We found that simple-express-react-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.