As I set up Bearer Token authentication for my Loopback 4 application, I referenced this implementation guide: https://github.com/strongloop/loopback-next/tree/master/packages/authentication.
Within my
src/providers/auth-strategy.provider.ts
file, I encountered an issue when trying to utilize the @repository
decorator to inject a repository object into the constructor for data querying purposes.
The problem arises when calling findOne()
on the repository reference initialized by the @repository
decorator, resulting in the error:
TypeError: Cannot read property 'findOne' of undefined
Below is the code snippet from my version of auth-strategy.provider.ts
:
import {Provider, inject, ValueOrPromise} from '@loopback/context';
import {Strategy} from 'passport';
import {
AuthenticationBindings,
AuthenticationMetadata,
} from '@loopback/authentication';
import {IVerifyOptions} from 'passport-http-bearer';
import {ApiClient} from '../models';
import {ApiClientRepository} from '../repositories';
import {Strategy as BearerStrategy} from 'passport-http-bearer';
import {repository} from '@loopback/repository';
// Rest of the TypeScript code...