Giter Site home page Giter Site logo

Comments (6)

MohammedFaragallah avatar MohammedFaragallah commented on May 24, 2024 3

hello, @cantoute if you follow docs everything should work the same but for some reason, its a very frustrating experience to make everything work the first time here is an example.

you should create a new auth management service

authmanagement.service.ts

import { ServiceAddons } from "@feathersjs/feathers";
import authManagement, {
  AuthManagementService
} from "feathers-authentication-management-ts";

import { Application } from "../../declarations";
import hooks from "./authmanagement.hooks";
import { notifier } from "./notifier";

// Add this service to the service type index
declare module "../../declarations" {
  interface ServiceTypes {
    authManagement: AuthManagementService & ServiceAddons<any>;
  }
}

export default function(app: Application) {
  app.configure(
    authManagement({
      skipIsVerifiedCheck: true,
      notifier: notifier(app)
    })
  );

  const service = app.service("authManagement");

  service.hooks(hooks);
}

authmanagement.hooks.ts

import * as authentication from "@feathersjs/authentication";
import { iff } from "feathers-hooks-common";
// Don't remove this comment. It's needed to format import lines nicely.

const { authenticate } = authentication.hooks;

const isAction = (...params: any): any => {
  const args = Array.from(params);
  return (hook: any) => args.includes(hook.data.action);
};

export default {
  before: {
    all: [],
    find: [],
    get: [],
    create: [
      iff(isAction("passwordChange", "identityChange"), authenticate("jwt"))
    ],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
};

notifier should be of type notifier example

(app: FeathersApplication) =>  (type: AuthManagementTypes, user: any) => Promise<any>

add auth management hooks to your users service

users.hooks.ts

import * as feathersAuthentication from "@feathersjs/authentication";
import * as local from "@feathersjs/authentication-local";
import { hooks } from "feathers-authentication-management-ts";
import { iff, isProvider, preventChanges } from "feathers-hooks-common";
// Don't remove this comment. It's needed to format import lines nicely.

const { authenticate } = feathersAuthentication.hooks;
const { hashPassword, protect } = local.hooks;

export default {
  before: {
    all: [],
    find: [],
    get: [],
    create: [hashPassword("password"), hooks.addVerification()],
    update: [hashPassword("password"), authenticate("jwt")],
    patch: [
      iff(
        isProvider("external"),
        preventChanges(
          true,
          "isVerified",
          "verifyToken",
          "verifyShortToken",
          "verifyExpires",
          "verifyChanges",
          "resetToken",
          "resetShortToken",
          "resetExpires"
        ),
        hashPassword("password"),
        authenticate("jwt")
      )
    ],
    remove: [authenticate("jwt")]
  },

  after: {
    all: [
      // Make sure the password field is never sent to the client
      // Always must be the last hook
      protect("password")
    ],
    find: [],
    get: [],
    create: [hooks.removeVerification()],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
};

I hope this helps please let me know if you face any more issues.

from feathers-authentication-management-ts.

meditatingdragon avatar meditatingdragon commented on May 24, 2024 2

I was trying the ts branch earlier today and ran into some issues with running just on the ts library. I thought everything was working fine until I removed the original library and ran into some callback function issues. I reverted back to the original feathers-authentication-management library to focus on getting something done and released, but can revisit later. Would also like to port this library over to TS as I'm building out my project in TS.

@cantoute I've open-sourced a frontend and backend implementation you may find useful: https://github.com/meditatingdragon/quasar-feathersjs-user-management/

I've been using the same frontend to test the typescript backend.

from feathers-authentication-management-ts.

cantoute avatar cantoute commented on May 24, 2024 1

hi,

I took the initiative to start building a usable exemple.

here is how far I got: https://github.com/cantoute/feathers-authentication-management-ts-example/blob/example/step-by-step/stepByStep.md

feel free to comment, add issues etc...

from feathers-authentication-management-ts.

MohammedFaragallah avatar MohammedFaragallah commented on May 24, 2024

excellent, so everything is working for you now?

from feathers-authentication-management-ts.

cantoute avatar cantoute commented on May 24, 2024

I haven't tested anything yet.
I tried improve where I could but some many details missing...
You think you could improve things there?

from feathers-authentication-management-ts.

cantoute avatar cantoute commented on May 24, 2024

Going to look at that 👍 thanks so much

On my exemple I'm missing dealing with the verify link
So far I've tested user creation and email is sent :)

Finally I rolled back on this

One change I made is that notifier.ts returns just the notifier function (not wrapped with {service: 'users', notifier: ...}

I thought it made more sens for in auth-management.service.ts

  app.configure(
    authManagement({
      skipIsVerifiedCheck: true,
      service: 'users',
      notifier: notifier(app),
    })
  );

does it make sens ?
or am I missing out something?

from feathers-authentication-management-ts.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.