mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 17:51:49 +10:00
feat: wip
This commit is contained in:
21
packages/lib/utils/token-verification.ts
Normal file
21
packages/lib/utils/token-verification.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import type { DurationLike } from 'luxon';
|
||||
import { DateTime } from 'luxon';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
/**
|
||||
* Create a token verification object.
|
||||
*
|
||||
* @param expiry The date the token expires, or the duration until the token expires.
|
||||
*/
|
||||
export const createTokenVerification = (expiry: Date | DurationLike) => {
|
||||
const expiresAt = expiry instanceof Date ? expiry : DateTime.now().plus(expiry).toJSDate();
|
||||
|
||||
return {
|
||||
expiresAt,
|
||||
token: nanoid(32),
|
||||
};
|
||||
};
|
||||
|
||||
export const isTokenExpired = (expiresAt: Date) => {
|
||||
return expiresAt < new Date();
|
||||
};
|
||||
Reference in New Issue
Block a user