New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-account-block

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-account-block

User accounts middleware for Express on top of Passport

  • 1.6.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-53.85%
Maintainers
1
Weekly downloads
 
Created
Source

express-account-block

npm version

A simple to use module for Express that handles authentification (signup and login), sessions and provide an account page you can place in your app.

Requires JQuery and Bootstrap 4 (JS + CSS) on the client side.

Features

  • Handles sessions and cookies
  • OAuth (Google and Github)
  • Drop-in login/signup page
  • Drop-in account management page
  • Forgot Password / reset link
  • Auto redirecting back after login/signup
  • Logged middleware
  • Ability to disable sign ups
  • Use Bootstrap
  • Magic link login
  • Store last logged date for users

Who uses it?

NucleusElioPayBackeryAnygoalLttrfeedMusli.io

👋 Want to be listed there? Contact me.

Usage

npm i express-account-block

Then in your express code


// Init express
const express 		= require('express')
const app 			= express()

// Add your DB
const mongoose      = require('mongoose')
const mongoURI 		= process.env.MONGO_URL || 'mongodb://localhost:27017/myappdb'
mongoose.connect(mongoURI, { useNewUrlParser: true })

// Your db schmeas
const db 			= require('./helpers/db')

// Parse from html forms and post payload
app.use(express.json()) 
app.use(express.urlencoded({ extended: true }))

// For signup and login
require('express-account-block')(app, {
	siteName: 'My Web App',
	siteUrl: 'example.com',
	mongoose: mongoose,
	useAccessToken: true, // Access token management
	redirectLogin: '/account',
	redirectSignup: '/account',
	// disableSignup: true,
	// signupMailExtra: 'You can now create your first app.',
	mongoUser: db.User,
	connectors: {
		github: {
			clientId: "xxxxxxx",
			clientSecret: "xxxxxx",
			redirectUri: "https://my.app/auth/github/callback"
		},
		google: {
			clientId: 'xxxxxxx.apps.googleusercontent.com',
			clientSecret: 'xxxxxxxxx',
			redirectUri: 'https://my.app/auth/google/callback'
		}
	},
	pages: {
		logoUrl: '/logo.png',
		customHeadHtml: `
			<link href="https://fonts.googleapis.com/css?family=Muli:400,800,900&display=swap" rel="stylesheet">
			<link rel="stylesheet" type="text/css" href="/css/login.css">
		`,
		// login: {
		// 	title: 'Good to have you back',
		// 	subtitle: 'Sign in and keep rocking your companies goals.'
		// },
	}
})

// Then you can use the provided middleware to enforce user to be logged
// Redirects to login and back to page if not logged
// Supports API token access
// User object will be assigned to res.locals.user
const logged = require('express-account-block/logged')(db.User)

app.get('/dashboard', logged, (req, res, next) => {
	const user = res.locals.user

	...
})


Account page

Will require Bootstrap and jQuery.

In your express route:

app.get("/account", (req, res, next) => {

	res.render("my_account_view", { // Where account is your page structure
		accountTemplate: require.resolve("express-account-block/account.ejs")
	})
})

Make sure to have Bootstrap.js and jQuery included.

Then, in your ejs:

<body>
	<%- include(accountTemplate) %>
</body>

<script src="/account/account.js" defer></script>

Oauth

Currently the module supports Github and Google oauth.

The redirect URIs are predefined paths:

  • /auth/github/callback for Github
  • /auth/google/callback for Google

FAQs

Package last updated on 01 Mar 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc