Skip to content

Commit 06900f0

Browse files
authored
fix: dont lose this reference for loggers (#708)
1 parent 317916e commit 06900f0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ export function createAppAuth(options: StrategyOptions): AuthInterface {
4141
);
4242
}
4343

44-
const log = Object.assign(
45-
{
46-
warn: console.warn.bind(console),
47-
},
48-
options.log,
49-
);
44+
/**
45+
* Mutate the logger to ensure it has a `warn` method.
46+
*
47+
* Some Loggers like pino need that the `this` reference points
48+
* to the original object, so we cannot use `Object.assign` here.
49+
*/
50+
const log = options.log || ({} as NonNullable<StrategyOptions["log"]>);
51+
if (typeof log.warn !== "function") {
52+
log.warn = console.warn.bind(console);
53+
}
54+
5055
const request =
5156
options.request ||
5257
defaultRequest.defaults({

0 commit comments

Comments
 (0)