Coder Social home page Coder Social logo

express-account-block's Introduction

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 after login/signup
  • Logged middleware
  • Ability to disable sign ups
  • Use Bootstrap
  • Magic link login
  • Store last logged date for users

Who uses it?

Nucleus ElioPay Backery Lttrfeed Musli.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',
	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-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

express-account-block's People

Contributors

vincelwt avatar loiclw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.