mbkauthe 4.1.1 → 4.1.3

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/index.js CHANGED
@@ -99,4 +99,5 @@ export {
99
99
  ErrorCodes, ErrorMessages, getErrorByCode,
100
100
  createErrorResponse, logError
101
101
  } from "./lib/utils/errors.js";
102
+ export { mbkautheVar } from "./lib/config/index.js";
102
103
  export default router;
@@ -36,8 +36,6 @@ function validateConfiguration() {
36
36
  if (mbkauthShared && typeof mbkauthShared !== 'object') {
37
37
  console.warn('[mbkauthe] mbkauthShared is not a valid object, ignoring it');
38
38
  mbkauthShared = null;
39
- } else {
40
- console.log('[mbkauthe] mbkauthShared detected and parsed successfully');
41
39
  }
42
40
  }
43
41
  } catch (error) {
@@ -46,6 +44,8 @@ function validateConfiguration() {
46
44
  }
47
45
 
48
46
  // Merge fallback settings: for any key missing or empty in mbkautheVar, check mbkauthShared
47
+ const usedFromShared = [];
48
+ const usedDefaults = [];
49
49
  const applyFallback = (source, sourceName) => {
50
50
  if (!source) return;
51
51
  Object.keys(source).forEach(key => {
@@ -53,7 +53,7 @@ function validateConfiguration() {
53
53
  if ((mbkautheVar[key] === undefined || (typeof mbkautheVar[key] === 'string' && mbkautheVar[key].trim() === '')) &&
54
54
  val !== undefined && !(typeof val === 'string' && val.trim() === '')) {
55
55
  mbkautheVar[key] = val;
56
- console.log(`[mbkauthe] Using ${key} from ${sourceName}`);
56
+ if (sourceName === 'mbkauthShared') usedFromShared.push(key);
57
57
  }
58
58
  });
59
59
  };
@@ -86,10 +86,10 @@ function validateConfiguration() {
86
86
  if (isEmpty) {
87
87
  if (mbkauthShared && mbkauthShared[key] !== undefined && !(typeof mbkauthShared[key] === 'string' && mbkauthShared[key].trim() === '')) {
88
88
  mbkautheVar[key] = mbkauthShared[key];
89
- console.log(`[mbkauthe] Using ${key} from mbkauthShared`);
89
+ if (!usedFromShared.includes(key)) usedFromShared.push(key);
90
90
  } else if (defaults[key] !== undefined) {
91
91
  mbkautheVar[key] = defaults[key];
92
- console.log(`[mbkauthe] Using default value for ${key}`);
92
+ usedDefaults.push(key);
93
93
  }
94
94
  }
95
95
  });
@@ -209,7 +209,16 @@ function validateConfiguration() {
209
209
  throw new Error(`[mbkauthe] Configuration Validation Failed:\n - ${errors.join('\n - ')}`);
210
210
  }
211
211
 
212
- console.log('[mbkauthe] Configuration validation passed successfully');
212
+ // Print consolidated configuration summary
213
+ const configParts = [];
214
+ if (mbkauthShared) {
215
+ configParts.push(`mbkauthShared: ${usedFromShared.length} keys`);
216
+ }
217
+ if (usedDefaults.length > 0) {
218
+ configParts.push(`defaults: ${usedDefaults.length} keys`);
219
+ }
220
+ const configSummary = configParts.length > 0 ? ` (${configParts.join(', ')})` : '';
221
+ console.log(`[mbkauthe] Configuration loaded${configSummary}`);
213
222
  return mbkautheVar;
214
223
  }
215
224
 
@@ -6,18 +6,13 @@ import { clearSessionCookies, cachedCookieOptions, readAccountListFromCookie } f
6
6
  async function validateSession(req, res, next) {
7
7
  if (!req.session.user) {
8
8
  console.log("[mbkauthe] User not authenticated");
9
- const remembered = readAccountListFromCookie(req) || [];
10
- const hasRemembered = remembered.some(acct => acct && typeof acct.sessionId === 'string' && acct.sessionId.length > 0);
11
- const pageTarget = hasRemembered ? '/mbkauthe/accounts' : `/mbkauthe/login?redirect=${encodeURIComponent(req.originalUrl)}`;
12
- const message = hasRemembered
13
- ? "Another saved account is available. Open the switch page to continue."
14
- : "You Are Not Logged In. Please Log In To Continue.";
15
- return renderError(res, req, {
9
+ console.log("[mbkauthe]: ", req.session.user);
10
+ return renderError(res, {
16
11
  code: 401,
17
12
  error: "Not Logged In",
18
- message,
19
- pagename: hasRemembered ? "Switch Account" : "Login",
20
- page: pageTarget,
13
+ message: "You Are Not Logged In. Please Log In To Continue.",
14
+ pagename: "Login",
15
+ page: `/mbkauthe/login?redirect=${encodeURIComponent(req.originalUrl)}`,
21
16
  });
22
17
  }
23
18
 
@@ -108,6 +108,9 @@ const createOAuthStrategy = async (provider, profile, done) => {
108
108
  }
109
109
  };
110
110
 
111
+ // Configure OAuth strategies and track enabled providers
112
+ const enabledProviders = [];
113
+
111
114
  // Configure GitHub Strategy for login (only if enabled and configured)
112
115
  if ((mbkautheVar.GITHUB_LOGIN_ENABLED || "").toLowerCase() === "true") {
113
116
  if (mbkautheVar.GITHUB_CLIENT_ID && mbkautheVar.GITHUB_CLIENT_SECRET) {
@@ -119,12 +122,10 @@ if ((mbkautheVar.GITHUB_LOGIN_ENABLED || "").toLowerCase() === "true") {
119
122
  }, (accessToken, refreshToken, profile, done) =>
120
123
  createOAuthStrategy('GitHub', profile, done)
121
124
  ));
122
- console.log('[mbkauthe] GitHub OAuth strategy registered');
125
+ enabledProviders.push('GitHub');
123
126
  } else {
124
127
  console.warn('[mbkauthe] GITHUB_LOGIN_ENABLED is true but GITHUB_CLIENT_ID/SECRET missing; skipping GitHub strategy registration');
125
128
  }
126
- } else {
127
- console.log('[mbkauthe] GitHub OAuth not enabled; skipping GitHub strategy registration');
128
129
  }
129
130
 
130
131
  // Configure Google Strategy for login (only if enabled and configured)
@@ -138,12 +139,15 @@ if ((mbkautheVar.GOOGLE_LOGIN_ENABLED || "").toLowerCase() === "true") {
138
139
  }, (accessToken, refreshToken, profile, done) =>
139
140
  createOAuthStrategy('Google', profile, done)
140
141
  ));
141
- console.log('[mbkauthe] Google OAuth strategy registered');
142
+ enabledProviders.push('Google');
142
143
  } else {
143
144
  console.warn('[mbkauthe] GOOGLE_LOGIN_ENABLED is true but GOOGLE_CLIENT_ID/SECRET missing; skipping Google strategy registration');
144
145
  }
145
- } else {
146
- console.log('[mbkauthe] Google OAuth not enabled; skipping Google strategy registration');
146
+ }
147
+
148
+ // Print consolidated OAuth summary
149
+ if (enabledProviders.length > 0) {
150
+ console.log(`[mbkauthe] OAuth providers: ${enabledProviders.join(', ')}`);
147
151
  }
148
152
 
149
153
  // Serialize/Deserialize user for OAuth login
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mbkauthe",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "description": "MBKTech's reusable authentication system for Node.js applications.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,13 +29,13 @@
29
29
  <i class="fab fa-github"></i>
30
30
  <span>Continue with GitHub</span>
31
31
  </a>
32
- {{/if }}
32
+ {{/if}}
33
33
  {{#if googleLoginEnabled }}
34
34
  <a type="button" id="googleLoginBtn" class="btn-social btn-google-side">
35
35
  <i class="fab fa-google"></i>
36
36
  <span>Continue with Google</span>
37
37
  </a>
38
- {{/if }}
38
+ {{/if}}
39
39
  <a href="/mbkauthe/accounts" id="switchacc" class="btn-social btn-switch-side">
40
40
  <i class="fa fa-user-group"></i>
41
41
  <span>Switch Account</span>
@@ -68,7 +68,7 @@
68
68
  <a class="terms-link" href="/mbkauthe/accounts">switch account</a>.
69
69
  </div>
70
70
  </div>
71
- {{/if }}
71
+ {{/if}}
72
72
  <input type="hidden" name="_csrf" value="{{csrfToken}}">
73
73
  <div class="form-group">
74
74
  <input id="loginUsername" class="form-input" type="text" name="username" placeholder=" "
@@ -312,7 +312,7 @@
312
312
  }
313
313
  });
314
314
 
315
- { { #if githubLoginEnabled } }
315
+ {{#if githubLoginEnabled }}
316
316
 
317
317
  // GitHub login: Navigate directly to GitHub OAuth flow
318
318
  async function startGithubLogin() {
@@ -328,9 +328,9 @@
328
328
  const mobileGithubBtn = document.querySelector('.mobile-github-btn');
329
329
  if (githubBtn) githubBtn.addEventListener('click', startGithubLogin);
330
330
  if (mobileGithubBtn) mobileGithubBtn.addEventListener('click', startGithubLogin);
331
- { {/if } }
331
+ {{/if}}
332
332
 
333
- { { #if googleLoginEnabled } }
333
+ {{#if googleLoginEnabled }}
334
334
 
335
335
  // Google login: Navigate directly to Google OAuth flow
336
336
  async function startGoogleLogin() {
@@ -346,7 +346,7 @@
346
346
  const mobileGoogleBtn = document.querySelector('.mobile-google-btn');
347
347
  if (googleBtn) googleBtn.addEventListener('click', startGoogleLogin);
348
348
  if (mobileGoogleBtn) mobileGoogleBtn.addEventListener('click', startGoogleLogin);
349
- { {/if } }
349
+ {{/if}}
350
350
  </script>
351
351
  </body>
352
352