@lamalibre/create-portlama 1.0.21 → 1.0.22

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": "@lamalibre/create-portlama",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "One-command setup for secure reverse tunnels with a management dashboard",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -224,14 +224,39 @@ function generateInvitePageHtml() {
224
224
  function showSuccess(result) {
225
225
  app.className = 'card success-card';
226
226
  var loginBtn = result.loginUrl
227
- ? '<a href="' + escapeHtml(result.loginUrl) + '" class="btn" style="text-decoration:none;text-align:center;display:block">Go to Login</a>'
227
+ ? '<a href="' + escapeHtml(result.loginUrl) + '" class="btn" style="text-decoration:none;text-align:center;display:block;margin-top:1rem">Go to Login</a>'
228
228
  : '';
229
- app.innerHTML =
230
- '<div class="icon">\\u2705</div>' +
231
- '<h1>Account Created</h1>' +
232
- '<p>Your account <strong style="color:#22d3ee">' + escapeHtml(result.username) + '</strong> has been created successfully.</p>' +
233
- '<p>On your first login, you will be asked to set up two-factor authentication (TOTP) using an authenticator app.</p>' +
234
- loginBtn;
229
+
230
+ if (result.totpUri) {
231
+ app.innerHTML =
232
+ '<div class="icon">\\u2705</div>' +
233
+ '<h1>Account Created</h1>' +
234
+ '<p>Your account <strong style="color:#22d3ee">' + escapeHtml(result.username) + '</strong> has been created.</p>' +
235
+ '<p style="margin-bottom:1.5rem">Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.) to set up two-factor authentication.</p>' +
236
+ '<div id="qr-container" style="display:flex;justify-content:center;margin-bottom:1.5rem;background:#fff;border-radius:0.5rem;padding:1rem;max-width:220px;margin-left:auto;margin-right:auto"></div>' +
237
+ '<p style="font-size:0.75rem;color:#52525b;margin-bottom:1rem;word-break:break-all"><strong style="color:#a1a1aa">Manual entry:</strong> ' + escapeHtml(result.totpUri.match(/secret=([^&]+)/)?.[1] || '') + '</p>' +
238
+ '<div class="error-msg" style="background:#0f1c1c;border-color:#134e4a;color:#5eead4;text-align:center">\\u26A0\\uFE0F Save this before navigating away — it cannot be shown again.</div>' +
239
+ loginBtn;
240
+
241
+ // Load QR code library and render
242
+ var script = document.createElement('script');
243
+ script.src = 'https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js';
244
+ script.onload = function() {
245
+ var qr = qrcode(0, 'M');
246
+ qr.addData(result.totpUri);
247
+ qr.make();
248
+ var container = document.getElementById('qr-container');
249
+ if (container) container.innerHTML = qr.createSvgTag(4, 0);
250
+ };
251
+ document.head.appendChild(script);
252
+ } else {
253
+ app.innerHTML =
254
+ '<div class="icon">\\u2705</div>' +
255
+ '<h1>Account Created</h1>' +
256
+ '<p>Your account <strong style="color:#22d3ee">' + escapeHtml(result.username) + '</strong> has been created successfully.</p>' +
257
+ '<p>Contact your administrator to set up two-factor authentication.</p>' +
258
+ loginBtn;
259
+ }
235
260
  }
236
261
 
237
262
  function escapeHtml(str) {
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { readInvitations, writeInvitations } from '../lib/state.js';
3
- import { createUserFromInvitation, hashPassword, readUsersRaw } from '../lib/authelia.js';
3
+ import { createUserFromInvitation, hashPassword, readUsersRaw, generateTotpSecret, writeTotpToDatabase } from '../lib/authelia.js';
4
4
  import { getConfig } from '../lib/config.js';
5
5
 
6
6
  const AcceptInvitationSchema = z.object({
@@ -101,6 +101,17 @@ export default async function inviteRoutes(fastify, _opts) {
101
101
  return reply.code(500).send({ error: 'Failed to create user account' });
102
102
  }
103
103
 
104
+ // Generate TOTP so the user can scan the QR code immediately
105
+ let totpUri = null;
106
+ try {
107
+ const { secret, uri } = generateTotpSecret(invitation.username);
108
+ await writeTotpToDatabase(invitation.username, secret);
109
+ totpUri = uri;
110
+ } catch (err) {
111
+ request.log.error(err, 'Failed to generate TOTP for invited user');
112
+ // Non-fatal: user was created, they can have admin reset TOTP later
113
+ }
114
+
104
115
  // Mark invitation as used
105
116
  invitation.used = true;
106
117
  invitation.acceptedAt = new Date().toISOString();
@@ -118,6 +129,7 @@ export default async function inviteRoutes(fastify, _opts) {
118
129
  ok: true,
119
130
  username: invitation.username,
120
131
  loginUrl,
132
+ totpUri,
121
133
  };
122
134
  });
123
135
  }