简体   繁体   中英

What is class in feathersjs and how to implement

Am new to feathersjs am try to do local auth in feathers while creating the service under users.class.js file where there. i don't know what to implement there so kindly guide me with this

const { Service } = require('feathers-mongoose');

exports.Users = class Users extends Service {
  create(Users, email, username, password, role ) {
    Users.created_at = new Date();

    return super.create(Users, email, username, password, role );
  }
  update(id, Users, users) {
    Users.updated_at = new Date();

    return super.update(id, Users, users);
  }
};

I'd look at the docs to learn more about services.

In Feathers, when you generate a service through the CLI, it creates three files. service-name.class.js/.ts contains your service definition. Feathers operates everything in a CRUD fashion. So, you'll see all the CRUD methods here. You can either define the service yourself, or use CLI to define it for you using an adaptor like Mongoose or Sequelize.

service-name.hooks.js/.ts contains all the hooks associated with this service. Feathers likes to keep your logic simple and clean, opting to do things like validation through reusable hooks instead of modifying the service logic directly. You said you wanted to add authentication to your service. This is where you would do it. In the before:[] hook section, add the authenticate(“jet”) hook your the methods you want to require authentication for.

service-name.service.js/.ts just handles service registration with the framework. Starting out, I wouldn't mess around with this file much. It just performs some setup so the framework knows your service exists and attaches it to a specific route like /users .

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM