|
| 1 | +/** |
| 2 | + * @module Auth/JWT |
| 3 | + */ |
| 4 | + |
1 | 5 | import jsonwebtoken from 'jsonwebtoken'; |
2 | 6 |
|
3 | 7 | /** |
4 | 8 | * Generates a JSON Web Token (JWT) for the specified admin ID and expiration time. |
5 | | - * |
6 | 9 | * @function |
7 | | - * @memberof JWT |
8 | | - * @param {string} adminID - The ID of the admin for whom the token is generated. |
| 10 | + * @param {string} adminID - The ID for whom the token is generated. |
9 | 11 | * @param {string | number} expiresIn - The expiration time for the token (e.g., '2h', '7d', or a timestamp). |
10 | | - * @param {string} secretKey - Security secretKey. |
11 | | - * @returns {string} The generated JWT. |
| 12 | + * @param {string} secretKey - The secret key used to sign the JWT token. |
| 13 | + * @returns {string} The generated JWT token. |
12 | 14 | */ |
13 | 15 | const generateToken = (adminID, expiresIn, secretKey) => |
14 | 16 | jsonwebtoken.sign({ id: adminID }, secretKey, { |
15 | 17 | expiresIn, |
16 | 18 | }); |
17 | 19 |
|
18 | 20 | /** |
19 | | - * Verifies the authenticity of a JSON Web Token (JWT). |
20 | | - * |
| 21 | + * Verifies the authenticity of a JWT token. |
21 | 22 | * @function |
22 | | - * @memberof JWT |
23 | | - * @param {string} token - The JWT to be verified. |
24 | | - * @param {string} secretKey - The JWT secretKey used to be verify. |
25 | | - * @returns {object} The decoded payload of the verified JWT. |
26 | | - * @throws {Error} If the token verification fails. |
| 23 | + * @param {string} token - The JWT token to be verified. |
| 24 | + * @param {string} secretKey - The secret key used to verify the JWT token. |
| 25 | + * @returns {string} The decoded payload of the verified JWT. |
| 26 | + * @throws {Error} If the token is invalid or has expired. |
27 | 27 | */ |
28 | 28 | const verifyToken = (token, secretKey) => jsonwebtoken.verify(token, secretKey); |
29 | 29 |
|
30 | | -/** |
31 | | - * JSON Web Token (JWT) utility functions for token generation and verification. |
32 | | - * |
33 | | - * @namespace |
34 | | - * @typedef {Object} JWT |
35 | | - * @property {function} generateToken - Function to generate a JWT. |
36 | | - * @property {function} verifyToken - Function to verify the authenticity of a JWT. |
37 | | - */ |
38 | | - |
39 | 30 | export const JWT = { |
40 | 31 | generateToken, |
41 | 32 | verifyToken, |
|
0 commit comments