feathers-mongoose-casl
Version 2.1.2
Version 2.1.2
  • feathers-mongoose-casl
  • Docs
    • Migrating
    • START A NEW PROJECT
      • Generate a new project.
      • install feathers-mongoose-casl
      • feathers-logger
      • Update config
      • Add mongoose
      • Email service
      • App hooks
      • Import required services
      • Verify user and filter user fields
      • Swagger, Logger, BodyParser
      • Email templates
      • public HTML
      • Run the server
      • Create you first user
      • vs code snippet extension
      • Test Login
      • Dashboard
      • Create a new Service with casl&Dashboard
      • Posts Postman snippet
      • Add Admin role
      • Done!
    • Advanced
      • Security - eslint-plugin-security
      • Security - rate limiting
      • Development tools
    • Guides
      • Throw errors
      • Auth Flow
      • Authentication
      • Authouriztion
      • /me
      • Rules Cache
      • Create a new service
      • Custom service validtor client data
      • validators
        • Example of use
        • Types
        • Mongoose schema
      • Default value
      • $Populate
      • Upload service
      • Upload files
        • Create upload service
        • Sign File After Populate
        • Storage support
          • Google-cloud
      • Error
      • feathers Client examples
      • Dashboard
        • Dashboard Config
          • Field configuration
          • doc Layout
          • custom Fields
            • customElements
        • Online dashboard
        • Add to your react app
      • customized feathers-mongoose-casl/services
      • Redis - in progress
      • S3
      • Postman
      • Swagger
      • debug
    • Production
      • ENV
    • Feathers wiki
      • Good links
    • utils
      • send email example
      • Async For Each
      • Create heroku server
      • pick
      • vs code snippet extension
      • Persist user request
    • Ecosystem
    • TODO
    • Versions updates
Powered by GitBook
On this page

Was this helpful?

  1. Docs
  2. START A NEW PROJECT

Verify user and filter user fields

We need to add authentication to app.configure

PreviousImport required servicesNextSwagger, Logger, BodyParser

Last updated 5 years ago

Was this helpful?

Open src/authentication.js and update file you can copy the file content from

const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication');
const { LocalStrategy } = require('@feathersjs/authentication-local');
const { expressOauth } = require('@feathersjs/authentication-oauth');
const { NotAuthenticated } = require('@feathersjs/errors');

// Add this
const { pick } = require('feathers-mongoose-casl');

module.exports = app => {
  // Add this
  const verifyEmailConfig = app.get('feathers-mongoose-casl').verifyEmail;
  const applyIsVerifiedEmail = verifyEmailConfig && verifyEmailConfig.enabled;
  //
  const authentication = new AuthenticationService(app);

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());

  app.use('/authentication', authentication);
  app.configure(expressOauth());

  // Add this hooks
  app.service('authentication').hooks({
    before: {
      create: [
        (context) => {
          context.params.skipAbilitiesCheckFromAuthentication = true;
          return context;
        },
      ]
    },
    after: {
      create: [
        (context) => {
          const { user } = context.result;
          if (applyIsVerifiedEmail && !user.isVerified) {
            throw new NotAuthenticated('User Email is not yet verified.');
          }
          const pickMeReadFields = app.get('feathers-mongoose-casl').pickMeReadFields;

          context.dispatch = Object.assign({}, context.result, { user: pick(context.result.user, pickMeReadFields) })
          return context;
        },
      ]
    }
  });
};

  • If you can't found src/authentication.js file then run $ feathers g authentication

here