mbkauthe 1.4.1 → 2.0.0

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.
@@ -10,7 +10,7 @@ npm install mbkauthe
10
10
 
11
11
  ## Version
12
12
 
13
- Current Version: 1.4.1
13
+ Current Version: 1.4.2
14
14
 
15
15
  ## Registry
16
16
 
@@ -1,4 +1,4 @@
1
- name: Publish to npm
1
+ name: Publish to npm and GitHub Packages
2
2
  on:
3
3
  push:
4
4
  branches:
@@ -36,19 +36,52 @@ jobs:
36
36
  run: |
37
37
  for i in {1..3}; do npm install && break || sleep 10; done
38
38
 
39
+ - name: Check if version exists on npm
40
+ id: check_version
41
+ run: |
42
+ PACKAGE_NAME=$(node -p "require('./package.json').name")
43
+ VERSION=$(node -p "require('./package.json').version")
44
+ if npm view $PACKAGE_NAME@$VERSION version 2>/dev/null; then
45
+ echo "exists=true" >> $GITHUB_OUTPUT
46
+ echo "Version $VERSION already exists on npm"
47
+ else
48
+ echo "exists=false" >> $GITHUB_OUTPUT
49
+ echo "Version $VERSION does not exist, will publish"
50
+ fi
51
+
39
52
  - name: Publish to npm
53
+ if: steps.check_version.outputs.exists == 'false'
40
54
  run: npm publish
41
55
  env:
42
56
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43
57
 
58
+ - name: Check if version exists on GitHub Packages
59
+ id: check_github_version
60
+ run: |
61
+ VERSION=$(node -p "require('./package.json').version")
62
+ if curl -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
63
+ https://npm.pkg.github.com/@mibnekhalid/mbkauthe/$VERSION 2>/dev/null; then
64
+ echo "exists=true" >> $GITHUB_OUTPUT
65
+ echo "Version $VERSION already exists on GitHub Packages"
66
+ else
67
+ echo "exists=false" >> $GITHUB_OUTPUT
68
+ echo "Version $VERSION does not exist on GitHub Packages, will publish"
69
+ fi
70
+
71
+ - name: Modify package.json for GitHub Packages
72
+ if: steps.check_github_version.outputs.exists == 'false'
73
+ run: |
74
+ node -e "const pkg = require('./package.json'); pkg.name = '@mibnekhalid/mbkauthe'; pkg.publishConfig = { registry: 'https://npm.pkg.github.com' }; require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
75
+
44
76
  - name: Setup Node.js for GitHub Packages
77
+ if: steps.check_github_version.outputs.exists == 'false'
45
78
  uses: actions/setup-node@v3
46
79
  with:
47
80
  node-version: '18'
48
81
  registry-url: 'https://npm.pkg.github.com'
49
- scope: '@MIbnEKhalid'
50
82
 
51
83
  - name: Publish to GitHub Packages
84
+ if: steps.check_github_version.outputs.exists == 'false'
52
85
  run: npm publish
53
86
  env:
54
87
  NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Publish to npm](https://github.com/MIbnEKhalid/mbkauthe/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/MIbnEKhalid/mbkauthe/actions/workflows/publish.yml)
7
7
  [![CodeQL Advanced](https://github.com/MIbnEKhalid/mbkauthe/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/MIbnEKhalid/mbkauthe/actions/workflows/codeql.yml)
8
8
 
9
- **MBKAuth** is a reusable, production-ready authentication system for Node.js applications built by MBKTechStudio. It provides secure session management, two-factor authentication (2FA), role-based access control, and multi-application support out of the box.
9
+ **MBKAuth** is a reusable, production-ready authentication system for Node.js applications built by MBKTech.org. It provides secure session management, two-factor authentication (2FA), role-based access control, and multi-application support out of the box.
10
10
 
11
11
  ## ✨ Features
12
12
 
@@ -313,8 +313,8 @@ Found a bug or need help? Please [open an issue](https://github.com/MIbnEKhalid/
313
313
 
314
314
  - [npm Package](https://www.npmjs.com/package/mbkauthe)
315
315
  - [GitHub Repository](https://github.com/MIbnEKhalid/mbkauthe)
316
- - [MBKTechStudio](https://mbktechstudio.com)
316
+ - [MBKTech.org](https://mbktech.org)
317
317
 
318
318
  ---
319
319
 
320
- Made with ❤️ by [MBKTechStudio](https://mbktechstudio.com)
320
+ Made with ❤️ by [MBKTech.org](https://mbktech.org)
package/docs/api.md CHANGED
@@ -328,10 +328,77 @@ Displays MBKAuthe version information and configuration.
328
328
 
329
329
  #### `GET /mbkauthe/main.js`
330
330
 
331
- Serves the client-side JavaScript file.
331
+ Serves the client-side JavaScript file containing helper functions for authentication operations.
332
+
333
+ **Purpose:** Provides frontend JavaScript utilities including:
334
+ - `logout()` - Logout function with confirmation dialog and cache clearing
335
+ - `logoutuser()` - Alias for logout function
336
+ - `nuclearCacheClear()` - Comprehensive cache and storage clearing (preserves rememberedUsername)
337
+ - `getCookieValue(cookieName)` - Cookie retrieval helper
338
+ - `loadpage(url)` - Page navigation helper
339
+ - `formatDate(date)` - Date formatting utility
340
+ - `reloadPage()` - Page reload helper
341
+ - `checkSession()` - Session validity checker
332
342
 
333
343
  **Response:** JavaScript file (Content-Type: application/javascript)
334
344
 
345
+ **Usage:**
346
+ ```html
347
+ <script src="/mbkauthe/main.js"></script>
348
+ <button onclick="logout()">Logout</button>
349
+ ```
350
+
351
+ **Main Functions:**
352
+
353
+ **`logout()`**
354
+ - Shows confirmation dialog before logout
355
+ - Clears all caches except rememberedUsername
356
+ - Calls `/mbkauthe/api/logout` endpoint
357
+ - Redirects to home page on success
358
+
359
+ **`nuclearCacheClear()`**
360
+ - Clears service workers and cache storage
361
+ - Clears localStorage and sessionStorage (preserves rememberedUsername)
362
+ - Clears IndexedDB
363
+ - Clears cookies
364
+ - Forces page reload
365
+
366
+
367
+ ---
368
+
369
+ #### `GET /mbkauthe/test`
370
+
371
+ Test endpoint to verify authentication and display user session information.
372
+
373
+ **Authentication:** Session required
374
+
375
+ **Rate Limit:** 8 requests per minute
376
+
377
+ **Response:** HTML page displaying:
378
+ - Current username
379
+ - User role
380
+ - Logout button
381
+ - Quick links to info and login pages
382
+
383
+ **Example Response:**
384
+ ```html
385
+ <head>
386
+ <script src="/mbkauthe/main.js"></script>
387
+ </head>
388
+ <p>if you are seeing this page than User is logged in.</p>
389
+ <p>id: '${req.session.user.id}', UserName: '${req.session.user.username}', Role: '${req.session.user.role}', SessionId: '${req.session.user.sessionId}'</p>
390
+ <button onclick="logout()">Logout</button><br>
391
+ <a href="/mbkauthe/info">Info Page</a><br>
392
+ <a href="/mbkauthe/login">Login Page</a><br>
393
+ ```
394
+
395
+ **Usage:**
396
+ ```
397
+ GET /mbkauthe/test
398
+ ```
399
+
400
+ **Note:** This endpoint is primarily for testing and debugging authentication. It should not be used in production environments.
401
+
335
402
  ---
336
403
 
337
404
  ## Middleware Reference
@@ -347,7 +414,7 @@ import { validateSession } from 'mbkauthe';
347
414
  app.get('/protected', validateSession, (req, res) => {
348
415
  // User is authenticated
349
416
  const user = req.session.user;
350
- // user contains: { id, username, UserName, role, Role, sessionId, allowedApps }
417
+ // user contains: { id, username, UserName, role, Role, sessionId }
351
418
  res.send(`Welcome ${user.username}!`);
352
419
  });
353
420
  ```
@@ -369,7 +436,6 @@ req.session.user = {
369
436
  role: "NormalUser", // User role
370
437
  Role: "NormalUser", // User role (alias)
371
438
  sessionId: "abc123...", // 64-char hex session ID
372
- allowedApps: ["app1"] // Array of allowed applications
373
439
  }
374
440
  ```
375
441
 
@@ -836,6 +902,6 @@ For issues, questions, or contributions:
836
902
  ---
837
903
 
838
904
  **Last Updated:** November 17, 2025
839
- **Version:** 1.4.1
905
+ **Version:** 1.4.2
840
906
 
841
907
  [← Back to README](../README.md)
package/env.md CHANGED
@@ -54,7 +54,7 @@ DOMAIN=localhost
54
54
  **Description:** Your application's domain name.
55
55
 
56
56
  **Configuration:**
57
- - **Production:** Set to your actual domain (e.g., `mbktechstudio.com`)
57
+ - **Production:** Set to your actual domain (e.g., `mbktech.com`)
58
58
  - **Development:** Use `localhost` or set `IS_DEPLOYED=false`
59
59
  - **Subdomains:** When `IS_DEPLOYED=true`, sessions are shared across all subdomains
60
60