Socket
Book a DemoInstallSign in
Socket

express-tala

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

express-tala

An authorization package for express

1.0.0
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

express-tala

A lightweight nodejs package for adding authorization system on your express app.

Installation

Install this package with npm or yarn

  npm install express-tala
  yarn add express-tala

Usage

Configuration Options

  import {createConnection} from 'mysql2/promise';
  import { setTala, genToken, ensureUser, attachUser } from 'express-tala';
  import express from 'express';

  const dbConn = createPool({
    host: "localhost",
    user: "root",
    password: "",
    database: "test",
  });
  setTala(dbConn, {
      promise: true
  });

  const app = express();

  app.use(
    ensureUser(
      (req, res)=>{
        /**
        * This will get called if user is not authorized
        */
        res.send('Unauthorized request');
      },
      '/login' /* Paths to skip this check. array, string or regex */
    )
  );

  app.post('/login', (req, res)=>{
      if(req.userId){
          //User is already logged in;
          res.send(req.user);
          return;
      }
      //DO your password check
      const token = genToken(req, user_id);
      //Either you can set this as cookie or in request header
  });

  app.lister(3000, ()=>{
      console.log('Server started at port 3000');
  });

  setTala(dbConnection, { //mysql2 connection or pool
    promise: false, //true if connection is promise (mysql2 only)

    cookie: {
        name: 'user_key',
        signed: false //true if cookies are signed
    },

    header: 'Authorization', //The header name by which token will be sent

    /**
    * Provide table name for mysql2 or model for mongoose to
    * add a user property containing user info in req object
    */
    userModel: false,

    /**
    * coloumn names or fields you want to get from users table
    * In case of mysql2 provide array of fields
    * or a direct string as: "full_name as name, COUNT(id) AS any_count"
    * And in case of mongoose provide space separated names as: "name age another_field"
    */
    populate: false,
  });

Keywords

express

FAQs

Package last updated on 01 Mar 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.