1.1.0 • Published 5 years ago

express-account-pages v1.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

express-account-pages

npm i express-account-pages

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

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

Features

  • OAuth (Google and Github)
  • Drop-in login/signup page
  • Drop-in account management page
  • Logged middleware
  • Ability to disable sign ups
  • Use Bootstrap
  • Magic link option
  • Store last logged date for users

Who uses it?

👋 Want to be listed there? Contact me.

Usage

// 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-pages')(app, {
	siteName: 'My Web App',
	primaryColor: '#b90577',
	// background: 'red',
	// logoUrl: '/favicon.png',
	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'
		}
	}
})

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-pages/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 Github
1.1.0

5 years ago

1.0.0

5 years ago

0.6.0

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago