@dax-crafta/auth 2.1.3 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dax-crafta/auth",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "A powerful, flexible, and secure authentication plugin for the Crafta framework. Supports JWT, social login, 2FA, RBAC, audit logging, and enterprise-grade security features.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.js CHANGED
@@ -264,7 +264,7 @@ function auth(config = {}) {
264
264
  validators.handleValidation,
265
265
  async (req, res, next) => {
266
266
  try {
267
- const deviceInfo = { browser: req.headers['user-agent'], ip: req.ip };
267
+ const deviceInfo = { userAgent: req.headers['user-agent'], ip: req.ip };
268
268
  const result = await authService.login(req.body.email, req.body.password, deviceInfo);
269
269
 
270
270
  await safeAudit({
@@ -59,12 +59,25 @@ const createAuthMiddleware = (config) => {
59
59
  };
60
60
 
61
61
 
62
+ const extractToken = (req) => {
63
+ const authHeader = req.headers.authorization;
64
+ if (authHeader && authHeader.startsWith('Bearer ')) {
65
+ return authHeader.split(' ')[1];
66
+ }
67
+
68
+ if (req.headers['x-access-token']) {
69
+ return req.headers['x-access-token'];
70
+ }
71
+
72
+ return null;
73
+ };
74
+
62
75
  const verifyToken = (req, res, next) => {
63
- const header = req.headers.authorization;
64
- if (!header || !header.startsWith('Bearer ')) {
76
+ const token = extractToken(req);
77
+ if (!token) {
65
78
  return res.status(401).json({ success: false, error: 'No token provided' });
66
79
  }
67
- const token = header.split(' ')[1];
80
+
68
81
  try {
69
82
  const decoded = jwt.verify(token, config.env.JWT_SECRET);
70
83
  // keep minimal user data on req.user