diff --git a/src/index.ts b/src/index.ts index fc8614b..4da9f40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -154,12 +154,14 @@ JWTOption) => { crit }) - if (morePayloadNbf !== undefined) { - jwt = jwt.setNotBefore(morePayloadNbf) + const setNbf = "nbf" in morePayload ? morePayloadNbf : nbf; + if (setNbf !== undefined) { + jwt = jwt.setNotBefore(setNbf) } - if (morePayloadExp !== undefined) { - jwt = jwt.setExpirationTime(morePayloadExp) + const setExp = "exp" in morePayload ? morePayloadExp : exp; + if (setExp !== undefined) { + jwt = jwt.setExpirationTime(setExp) } return jwt.sign(key) diff --git a/test/index.test.ts b/test/index.test.ts index 664d8ac..c3a8391 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -27,10 +27,7 @@ describe('JWT Plugin', () => { .post( '/sign-token', ({ jwt, body }) => - jwt.sign({ - name: body.name, - exp: '30m' - }), + jwt.sign(body), { body: t.Object({ name: t.String()