feathersjs / feathers

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

Using API key authenticaion as per Feathers documentation causes TS compilation errors #3426

Open JPStrydom opened 4 months ago

JPStrydom commented 4 months ago

Steps to reproduce

Expected behavior

The API key authentication from the Feathers example should work and allow API key authentication.

Actual behavior

The provided example doesn't compile. I've also tried the following:

interface ServiceTypes {
    authentication: AuthenticationService; // & ServiceAddons<any>;
  }

Which resolves the initial issue, but then the following error occures:

src/authentication.ts:25:51 - error TS2339: Property 'apiKey' does not exist on type '{ entity?: string | null | undefined; entityId?: string | und
efined; service?: string | undefined; parseStrategies?: string[] | undefined; jwtOptions?: {} | undefined; jwt?: { header: string; schemes: string; } | undefined; local?: { ...; } | undefined; oauth?: { ...; } | undefined; secret: string; authStrategies: s...'.

25     const config = this.app.get('authentication').apiKey;
                                                     ~~~~~~

    at createTSError (path\to\project\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (path\to\project\node_modules\ts-node\src\index.ts:863:19)
    at getOutput (path\to\project\node_modules\ts-node\src\index.ts:1077:36)
    at Object.compile (path\to\project\node_modules\ts-node\src\index.ts:1433:41)
    at Module.m._compile (path\to\project\node_modules\ts-node\src\index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (path\to\project\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19) {
  diagnosticCodes: [ 2532, 2339 ]
}
[nodemon] app crashed - waiting for file changes before starting...

I'm sure I'm just missing something wrong with the TS typing, but not sure where to start.

System configuration

Module versions:

NodeJS version: v20.11.0

jordandenison commented 4 months ago

Have you tried adding that property to your configurationSchema in configuration.ts?