Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"expiresIn" doesn't work with string or number #153

Closed
salali opened this issue Jan 1, 2016 · 13 comments
Closed

"expiresIn" doesn't work with string or number #153

salali opened this issue Jan 1, 2016 · 13 comments

Comments

@salali
Copy link

salali commented Jan 1, 2016

Getting the error

"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60

I looked at where the error was being thrown in index.js line 86:

payload.exp = timespan(options.expiresIn);

I stepped through the timespan function and everything looks good there if I pass in either string or number. However the function always returns undefined?

@salali
Copy link
Author

salali commented Jan 2, 2016

I should have read the documentation better:

payload could be an object literal, buffer or string. Please note that exp is only set if the payload is an object literal.

I was sending in a string.

Closing as non-issue.

@salali salali closed this as completed Jan 2, 2016
@jgentes
Copy link

jgentes commented Jan 3, 2016

After updating to 5.5, I started seeing this error, whereas I wasn't seeing it before.

I am also passing a string in rather than an object literal, so I went ahead and removed the expiration since it's not being used and it cleared the error up.

However, this error message is incorrect - the format of "expiresIn" was correct, so this is an open bug in my opinion.

@jgentes
Copy link

jgentes commented Jan 3, 2016

Please re-open

@jfromaniello
Copy link
Member

Notice that it will be silently ignored now when the payload doesn't support expiration. I plan to fail explicitly in the next major version.

@MeRahulAhire
Copy link

Out of nowhere I'm facing exact same issue. First it was working fine and now its giving me this error
invalid expiresIn option for string payload

const accessToken = jwt.sign(phone, JWT_AUTH_TOKEN, { expiresIn: '30s' });
const refreshToken = jwt.sign(phone, JWT_REFRESH_TOKEN, { expiresIn: '1y' });

@skibaalex
Copy link

@MeRahulAhire
any solutions? I am facing the same issue

@nayabahmad
Copy link

Facing the same issue

@Xavek
Copy link

Xavek commented Oct 25, 2021

@nayabahmad You can check https://www.npmjs.com/package/jsonwebtoken the Token Expiration (exp claim) part.
I was also facing the same issue but this solved my problem

@xinthose
Copy link

xinthose commented Mar 27, 2022

Just make the payload an object:
Wrong: sign(data.username, ...
Right: sign({ "username": data.username }, ...

@kirilritobis
Copy link

Just make the payload an object: Wrong: sign(data.username, ... Right: sign({ "username": data.username }, ...

That solved the problem. Thank you

@juannguyenicd
Copy link

The type of payload to sign should be: 'object'

ref: https:/auth0/node-jsonwebtoken/blob/master/sign.js#L90

@hungify
Copy link

hungify commented Jun 3, 2023

You can only set expiresIn when that payload is an object.

Ref: https://community.auth0.com/t/i-need-some-help-with-jwt-expiresin-syntax/47333

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests