auth-verify 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
3
+ };
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "dependencies": {
3
+ "auth-verify": "^1.2.4",
3
4
  "axios": "^1.12.2",
4
5
  "crypto": "^1.0.1",
5
- "express": "^5.1.0",
6
6
  "ioredis": "^5.8.1",
7
7
  "jsonwebtoken": "^9.0.2",
8
8
  "node-telegram-bot-api": "^0.66.0",
9
9
  "nodemailer": "^7.0.6",
10
10
  "redis": "^5.8.3",
11
11
  "twilio": "^5.10.3",
12
- "uuid": "^13.0.0"
12
+ "uuid": "^9.0.1"
13
13
  },
14
14
  "name": "auth-verify",
15
- "version": "1.2.4",
16
- "description": "A simple Node.js library for sending and verifying OTP via email",
15
+ "version": "1.2.5",
16
+ "description": "A simple Node.js library for sending and verifying OTP via email, SMS and Telegram bot",
17
17
  "main": "index.js",
18
18
  "scripts": {
19
- "test": "node test.js"
19
+ "test": "jest --runInBand"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -47,5 +47,19 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/jahongir2007/auth-verify/issues"
49
49
  },
50
- "homepage": "https://jahongir2007.github.io/auth-verify/"
50
+ "homepage": "https://jahongir2007.github.io/auth-verify/",
51
+ "devDependencies": {
52
+ "@babel/preset-env": "^7.28.5",
53
+ "babel-jest": "^30.2.0",
54
+ "jest": "^30.2.0",
55
+ "supertest": "^7.1.4"
56
+ },
57
+ "jest": {
58
+ "transformIgnorePatterns": [
59
+ "node_modules/(?!(jsonwebtoken|ioredis)/)"
60
+ ],
61
+ "transform": {
62
+ "^.+\\.jsx?$": "babel-jest"
63
+ }
64
+ }
51
65
  }
package/src/jwt/index.js CHANGED
@@ -249,7 +249,7 @@ const CookieManager = require("./cookie");
249
249
  class JWTManager {
250
250
  constructor(secret, options = {}) {
251
251
  // if (!secret) throw new Error("JWT secret is required");
252
- this.secret = secret || "JWT_AUTH_VERIFY_SECRET";
252
+ this.secret = secret || "jwt_token";
253
253
  this.storeType = options.storeTokens || "none";
254
254
 
255
255
  if (this.storeType === "memory") {
@@ -307,7 +307,7 @@ class JWTManager {
307
307
 
308
308
  // Auto cookie support
309
309
  if (options.res) {
310
- CookieManager.setCookie(options.res, "jwt_token", token, {
310
+ CookieManager.setCookie(options.res, this.secret, token, {
311
311
  httpOnly: true,
312
312
  secure: options.secure ?? true,
313
313
  sameSite: "Strict",
@@ -325,7 +325,7 @@ class JWTManager {
325
325
  // If request object provided
326
326
  if (typeof input === "object" && input.headers) {
327
327
  token =
328
- CookieManager.getCookie(input, "jwt_token") ||
328
+ CookieManager.getCookie(input, this.secret) ||
329
329
  (input.headers.authorization
330
330
  ? input.headers.authorization.replace("Bearer ", "")
331
331
  : null);
@@ -0,0 +1,39 @@
1
+ // tests/jwtManager.test.js
2
+ const AuthVerify = require('../index');
3
+ const express = require('express');
4
+ const request = require('supertest'); // for API tests
5
+
6
+ describe('JWTManager', () => {
7
+ let auth;
8
+
9
+ beforeAll(() => {
10
+ auth = new AuthVerify({jwtSecret: 'test_secret', storeTokens: 'memory'});
11
+ });
12
+
13
+ test('should sign and verify a JWT', async () => {
14
+ const payload = { userId: 1 };
15
+ const token = await auth.jwt.sign(payload, '5s');
16
+ expect(typeof token).toBe('string');
17
+
18
+ const verified = await auth.jwt.verify(token);
19
+ expect(verified.userId).toBe(1);
20
+ });
21
+
22
+ test('should fail after expiration', async () => {
23
+ const token = await auth.jwt.sign({ name: 'Jahongir' }, '1s');
24
+ await new Promise(r => setTimeout(r, 2000)); // wait 2s
25
+ await expect(auth.jwt.verify(token)).rejects.toThrow(/expired/i);
26
+ });
27
+
28
+ test('should set cookie automatically if res is provided', async () => {
29
+ const app = express();
30
+
31
+ app.get('/login', async (req, res) => {
32
+ const token = await auth.jwt.sign({ userId: 123 }, '5s', { res });
33
+ res.json({ token });
34
+ });
35
+
36
+ const res = await request(app).get('/login');
37
+ expect(res.headers['set-cookie']).toBeDefined();
38
+ });
39
+ });
package/test.js DELETED
File without changes