feathers icon indicating copy to clipboard operation
feathers copied to clipboard

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

Open mrobst opened this issue 1 year ago • 0 comments

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? 

mrobst avatar Jan 29 '24 09:01 mrobst