feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

Minor issue with authentication generator if service name is not "user" #3412

Open mrobst opened 5 months ago

mrobst commented 5 months ago

Minor issue - running the feathers authentication generator appears to scaffold an authentication service which assumes the service is always called user.

To reproduce the error generate authentication per the documenatation:


? Which authentication methods do you want to use? Other methods and providers can be added at any time. Email + Password
? What is your authentication service name? admin
? What path should the service be registered on? admins
? What database is the service using? SQL
? Which schema definition format do you want to use? Schemas allow to type, validate, secure and populate data TypeBox
(recommended)```

The file admins.schema.ts will be generated with the following minor errors:

```export const adminQueryResolver = resolve<AdminQuery, HookContext<AdminService>>({
  // If there is a user (e.g. with authentication), they are only allowed to see their own data
  id: async (value, user, context) => {
    if (context.params.user) {    <-- user does not exist
      return context.params.user.id   <-- user does not exist
    }

    return value
  }
})```

Replacing the context.params.user with context.params.admin in two places resolves the issue. 

Perhaps the authentication generator should read the service schema id dynamically to improve this?