feat(user-auth): use ms library and update docs

This commit is contained in:
carlosmonastyrski
2025-04-30 16:49:33 -03:00
parent 6d5a6f42e0
commit c99440ba81
3 changed files with 9 additions and 18 deletions
+5 -18
View File
@@ -1,29 +1,16 @@
import ms, { StringValue } from "ms";
const convertToMilliseconds = (exp: string | number): number => { const convertToMilliseconds = (exp: string | number): number => {
if (typeof exp === "number") { if (typeof exp === "number") {
return exp * 1000; return exp * 1000;
} }
const match = exp.match(/^(\d+)\s*([a-z]*)$/i); const result = ms(exp as StringValue);
if (!match) { if (typeof result !== "number") {
throw new Error(`Invalid expiration format: ${exp}`); throw new Error(`Invalid expiration format: ${exp}`);
} }
const value = parseInt(match[1], 10); return result;
const unit = match[2].toLowerCase();
switch (unit) {
case "":
case "s":
return value * 1000; // seconds
case "m":
return value * 60 * 1000; // minutes
case "h":
return value * 60 * 60 * 1000; // hours
case "d":
return value * 24 * 60 * 60 * 1000; // days
default:
throw new Error(`Unsupported time unit: ${unit}`);
}
}; };
export const getMinExpiresIn = (exp1: string | number, exp2: string | number): string | number => { export const getMinExpiresIn = (exp1: string | number, exp2: string | number): string | number => {
@@ -27,6 +27,10 @@ The **Settings** page lets you manage information about your organization includ
![organization settings auth](../../images/platform/organization/organization-settings-auth.png) ![organization settings auth](../../images/platform/organization/organization-settings-auth.png)
<Tip>
You can adjust the maximum time a user token will remain valid for your organization. After this period, users will be required to re-authenticate. This helps improve security by enforcing regular sign-ins.
</Tip>
## Access Control ## Access Control
The **Access Control** page is where you can manage identities (both people and machines) that are part of your organization. The **Access Control** page is where you can manage identities (both people and machines) that are part of your organization.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 KiB

After

Width:  |  Height:  |  Size: 352 KiB