Authentication in Feathers JS without the need for email addresses

Currently, I am in need of an authentication system for my dApp that operates without using email addresses or storing any user information. What I require is an endpoint where users can submit a seed phrase and password to generate a JWT. The process should involve calculating a value based on the provided inputs, and if successful (which it usually will be unless invalid data is sent), issue a JWT. However, the default functionality with Feathers CLI seems to require local strategy and an email address, which does not align with my requirements. I have been unable to find any demos or examples to guide me through this specific setup. Any suggestions or pointers on how to achieve this would be greatly appreciated as my current authentication setup is quite basic.

const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const local = require('@feathersjs/authentication-local');


module.exports = function (app) {
  const config = app.get('authentication');

  // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(jwt());
  app.configure(local());

  // The `authentication` service is used to create a JWT.
  // The before `create` hook registers strategies that can be used
  // to create a new valid JWT (e.g. local or oauth2)
  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies)
      ],
      remove: [
        authentication.hooks.authenticate('jwt')
      ]
    }
  });
};

Below is the code snippet for my service:

// Initializes the `aerAuth` service on path `/userauthendpoint`
const createService = require('feathers-memory');
const hooks = require('./userauthendpoint.hooks');

module.exports = function (app) {

  const paginate = app.get('paginate');

  const options = {
    name: 'userauthendpoint',
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/userauthendpoint', createService(options) );

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('userauthendpoint');

  service.hooks(hooks);
};

Although I am relatively new to Feathers, I do have experience building authentication systems, particularly in PHP.

Answer №1

If you are searching for a way to implement custom authentication strategies, the Custom authentication strategy guide along with the feathers-authentication-custom plugin might meet your requirements.

The implementation can vary based on your preferences. You have the option of using the custom strategy for individual services (like requiring an API key in the request header) or just before the /authentication service for creating a JWT token (bearing in mind that it requires a valid userId or entityId which must exist in the database).

One simple approach is to opt for the former and utilize a custom header (X-DAP-PASSWORD) as demonstrated below:

const custom = require('feathers-authentication-custom');

app.configure(authentication(settings));
app.configure(custom((req, done) => {
  const password = req.headers['x-dap-password'];

  if(checkPassword(req.app.get('seedPassphrase'), password)) {
    // Here, you can add your own logic to load and verify the user
      done(null, user);
  } else {
    done(new Error('Invalid passphrase'));
  }
}));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The collection name is not being generated by Mongoose based on the variable

schema.js **************************************************************** var nameOfCategory = "hello"; ecomm.createProductCollection = async (categoryName) =>{ nameOfCategory = categoryName; } const productSchema = new mongoose.Schema({ ...

rearranging the sequence of buttons using JavaScript

I am faced with the challenge of making a series of buttons draggable and droppable within a parent div without using any external libraries at the request of the client. Although I could have easily accomplished this task with jQuery, it's an opportu ...

What is the correct way to terminate a docker container with a timeout setting?

I recently created a web-based IDE for testing user code within a Docker container. However, I encountered an issue where if a user runs an infinite loop like while(true), the Docker container will endlessly consume computer resources such as memory. To pr ...

Choosing a JSON item based on its numerical position rather than by its name

I am attempting to store a JSON object containing information in multiple languages. I am uncertain if the way I have implemented it is optimal, so any suggestions are appreciated. My current issue is that I am unsure how to access the first language with ...

Unable to modify document value in MongoDB using Node.js

Currently, I am attempting to fetch the value of a field form that is being sent to a subroute and utilize it to update a database collection. My ability to retrieve the form value and manipulate it is working fine; however, I encounter an issue when I sol ...

Struggling to set up the passport-jwt module? A common issue that arises is the error message stating, "Login sessions

Greetings! I have recently embarked on learning Node.js courses, and one of the topics covered registration and authentication using the MEAN stack. However, I encountered an issue with outdated code that was not compatible with updated modules. After add ...

Is the state mutated when using the .map() function to update it?

I am new to working with React and I am still struggling to understand state mutation. After reading multiple posts on this topic, I am finding it difficult to grasp the concept of state mutation. So, I have decided to seek clarification on this matter. ...

What is the best way to toggle the color of the circle div in the center between yellow and white with every click within the circle?

Up to now, I have successfully accomplished this with just one click. I deleted the lightbulb image const sphere = document.getElementById("sphere"); sphere.addEventListener("click", event => { console.log("You clicked the ...

Anonymous self-executing functions with parameters from an external scope

Recently, I stumbled upon the code snippet below while following a tutorial. const increment = (function(){ return function incrementbytwo (number){ return number+2; } })(); console.log(increment(1)); The result of the code above is 3. ...

Unable to view the token balances of the smart contract on remix while executing the seeBalance function

pragma solidity =0.7.6; pragma abicoder v2; import "https://github.com/Uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; interface IERC20 { function balanceOf(address account) external view returns (uint256); function transfer(address ...

Having trouble organizing a list of objects based on changing keys

Below is the implementation of a custom pipe designed to sort records: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'sortpipe' }) export class SortPipe implements PipeTransform { transfor ...

I have a Key in my component, but it is still searching for a unique key

Just diving into React JS and attempting to transfer data from one component to another using the Link to method I found online... Error: index.js:1 Warning: Each child in a list should have a unique "key" prop. Checking the render method of Videos. Refe ...

Encountering issues with implementing router.push in Reactjs

Currently, I am working on ReactJS and utilizing Next.js. My current task involves refreshing the page (using routes), but I encountered an error message stating: Error: No router instance found. You should only use "next/router" inside the client-side of ...

Numerous references embedded within a Vue.js component

I am currently working with multiple instances of a polygonCrop component in Vue.js, each one having a unique reference to a canvas property. These components are utilized in separate crop functions triggered by button clicks. My question is how to effecti ...

jQuery Autocomplete API Issue: Undefined

I've been attempting to implement a basic text box using the jQuery API from DevBridge. I followed instructions in this video tutorial to create my code. However, despite properly declaring scripts before the JS code and ensuring proper mappings, I&a ...

Achieving a perfect circle can be accomplished by setting both the width and height to the same

Trying to make the height of an element equal to its width For example, aiming for a perfect circle Although the console displays equal values, the resulting height is noticeably greater than the width $('button').on('click', funct ...

Display a dropdown list using ng-repeat to prevent selecting the same value multiple times

Within my ng-repeat loop, I have a drop-down menu and an add button that allows users to add new drop-down menus to the list. However, I am looking for a way to restrict the second drop-down menu from selecting the same value as the first one. In other wor ...

Sending AJAX information to multiple pages

I have created an HTML page where I am struggling to pass two variables using the POST method to a PHP page. The PHP page is supposed to accept these variables and then call an API to retrieve data based on them. However, my challenge is in receiving this ...

What is the best way to create a multiple options query using the MongoDB driver in Node.js?

I'm currently facing an issue with a MongoDB query in Node.js that I can't seem to solve. Let's say we have numerous documents in Mongo, each containing an array of tags. tags: [tag1, tag2, tag3] The front-end will be sending parameters a ...

Darkness prevails even in the presence of light

I'm currently in the process of developing a game engine using ThreeJS, and I have encountered an issue with lighting that I need assistance with. My project involves creating a grid-based RPG where each cell consists of a 10 x 10 floor and possibly ...