adonisjs/auth

Api token expiresIn expect milliseconds instead of secconds

Kuzzy opened this issue · 5 comments

Kuzzy commented

Package version

8.2.1

Docs says that expiresIn property should be in seconds:

image

But in real it awaits for milliseconds:

const milliseconds = typeof expiresIn === 'string' ? string.toMs(expiresIn) : expiresIn

I'm not sure where better to address this issue here or in repo with docs, but in my opinion it would be more user friendly to use seconds. For example, Redis setex, which is used under the hood (if storage is Redis), is using a seconds.

Alright, checked the codebase and docs both.

The docs you have shared links to the return value of auth.generate and not the config accepted. So basically, you are looking at the config property expiresIn and confusing it with the return value of auth.generate method

Feel free to reopen the issue if you have any questions

The docs are wrong for both ways of specify the value of expiresIn.

For numbers, it says seconds instead of milliseconds but doc says:

https://docs.adonisjs.com/guides/auth/api-tokens-guard#managing-tokens-expiry

for string it uses this format as an example: '7days' or '30mins' and is wrong according to ms documentation:

https://www.npmjs.com/package/ms

The right way of set it is including a white space '7 days' or '30 mins'

I have tested both cases. Please update the docs.

You have not even quoted the docs and asking me to fix it 🤷‍♂️

@thetutlage sorry link added! but im pretty sure you knew where to find it :P