We.js Authentication Plugin

2.3.4 · deprecated · verified Wed Apr 22

we-plugin-auth is an authentication plugin for the We.js Node.js MVC framework, providing integration with Passport.js for various authentication strategies, including local username/password, and remembering user sessions. It handles core authentication routes and mechanisms within a We.js application. The current stable version is 2.3.4. However, the core We.js framework is officially deprecated, with a recommendation to use a Golang port (`@go-catupiri`). Consequently, `we-plugin-auth` and its ecosystem are no longer actively maintained and should be considered deprecated for new projects or ongoing development. Its release cadence has ceased with the deprecation of We.js. Key differentiators included its deep integration with the We.js configuration system and opinionated approach to authentication within that framework.

Warnings

Install

Imports

Quickstart

Demonstrates the installation of `we-plugin-auth` via the We.js CLI and shows how to configure a local Passport.js strategy within a typical We.js application's configuration file (e.g., `config/locals.js`). This highlights the plugin's declarative configuration approach.

/*
  This quickstart demonstrates how to install we-plugin-auth into a We.js application
  and conceptually configure a local authentication strategy. We.js plugins
  are integrated via configuration rather than direct code imports.
*/

// 1. Install the plugin using the We.js CLI
// Run this command in your We.js project root:
// we i we-plugin-auth

// 2. Configure authentication strategies in your We.js application
// This typically happens in a file like 'config/locals.js' or
// 'config/environment/development.js' based on your environment.
// Create or update 'config/locals.js' with the following:

// const passport = require('passport'); // You might not directly require passport here
// const LocalStrategy = require('passport-local').Strategy;

module.exports = {
  passport: {
    strategies: {
      local: {
        // Example configuration for a local (username/password) strategy
        usernameField: 'email', // Define which field in your form is the username
        passwordField: 'password', // Define which field in your form is the password
        // The `verify` callback would typically be handled internally by we-plugin-auth
        // based on your user model and its authentication methods.
        // If custom logic is needed, it would usually involve extending We.js services.
      },
      // You would configure other Passport strategies (e.g., Facebook, Google)
      // through their respective 'we-plugin-passport-X' plugins here.
    },
    // Global Passport configuration for We.js
    serializeUser: (user, done) => { done(null, user.id); }, // Example, We.js handles this
    deserializeUser: (id, done) => { /* Lookup user by ID */ done(null, user); }, // We.js handles this

    // Redirect URLs after successful or failed authentication attempts
    redirectUrlAfterSuccess: '/dashboard',
    redirectUrlAfterFailure: '/login',
    loginForm: '/login', // Path to your login form
    registerForm: '/register' // Path to your registration form
  },

  // We.js lifecycle hooks for plugins (illustrative)
  // In a We.js plugin's `plugin.js`, it might register middleware or routes:
  // module.exports = function (we) {
  //   we.routes['post /login'] = { controller: 'auth', action: 'login' };
  //   we.express.use(passport.initialize());
  //   we.express.use(passport.session());
  // };

  // Ensure your We.js application has routes corresponding to these paths
  // and a user model with authentication methods compatible with passport-local.
};

// 3. Start your We.js application
// we s

view raw JSON →