elysiajs / elysia-jwt

Plugin for Elysia for using JWT Authentication
MIT License
41 stars 16 forks source link

Fix: `exp` type & overriding default `exp` value #28

Open damnmicrowave opened 6 months ago

damnmicrowave commented 6 months ago

Technically, jose supports passing timey strings, e.g. '1h', '10days' etc. (here) This PR updates the type of exp to be string as well as a number for that.

Also, this fixes overriding exp value when calling jwt.sign() method. Example:

const token = await jwt.sign({
  userId: 'qwbfo21b9d',
  exp: '1h', // <~ this now works fine. Previously this was ignored and threw a type error
})
fallow64 commented 3 months ago

I was so confused why my exp field was not being passed into my token; this would be a great QOL feature, and certainly would save others from hours of debugging.