Skip to content

Commit 468e7d0

Browse files
committed
🔧 fix: Use default exp and nbf if missing in jwt.sign payload
Fixes #101
1 parent f2fa002 commit 468e7d0

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

‎src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ JWTOption<Name, Schema>) => {
154154
crit
155155
})
156156

157-
if (morePayloadNbf !== undefined) {
158-
jwt = jwt.setNotBefore(morePayloadNbf)
157+
const setNbf = morePayloadNbf ?? nbf;
158+
if (setNbf !== undefined) {
159+
jwt = jwt.setNotBefore(setNbf)
159160
}
160161

161-
if (morePayloadExp !== undefined) {
162-
jwt = jwt.setExpirationTime(morePayloadExp)
162+
const setExp = morePayloadExp ?? exp;
163+
if (setExp !== undefined) {
164+
jwt = jwt.setExpirationTime(setExp)
163165
}
164166

165167
return jwt.sign(key)

‎test/index.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ describe('JWT Plugin', () => {
2727
.post(
2828
'/sign-token',
2929
({ jwt, body }) =>
30-
jwt.sign({
31-
name: body.name,
32-
exp: '30m'
33-
}),
30+
jwt.sign(body),
3431
{
3532
body: t.Object({
3633
name: t.String()

0 commit comments

Comments
 (0)