adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
187 stars 65 forks source link

Api token expiresIn expect milliseconds instead of secconds #202

Closed Kuzzy closed 1 year ago

Kuzzy commented 2 years ago

Package version

8.2.1

Docs says that expiresIn property should be in seconds:

image

But in real it awaits for milliseconds: https://github.com/adonisjs/auth/blob/946e730cdebcfd277cf69ce29d5be40c80a25ce0/src/Guards/Oat/index.ts#L125

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.

thetutlage commented 1 year ago

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

thetutlage commented 1 year ago

Feel free to reopen the issue if you have any questions

mcordoba commented 1 year ago

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.

thetutlage commented 1 year ago

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

mcordoba commented 1 year ago

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