# Verify user and filter user fields

Open src/authentication.js and update file\
\
you can copy the file content from [here](https://github.com/doronnahum/feathers-mongoose-casl/blob/master/lib/src/authentication.js)<br>

```
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` <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://feathersjs-mongoose.gitbook.io/feathers-mongoose-casl/docs/start-new-project-1/use-feathers-mongoose-casl-authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
