@egdesk/next-api-plugin 1.5.44 → 1.5.50
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/README.md +6 -1
- package/dist/generate-visitor-auth.js +46 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,12 @@ NEXT_PUBLIC_EGDESK_API_KEY=your-api-key-here
|
|
|
72
72
|
|
|
73
73
|
Published sites do **not** receive `SUPABASE_URL` or the anon key. Visitor Google sign-in is brokered by EGDesk: the site redirects through `{EGDESK_API}/visitor-auth`, EGDesk creates an Auth user, and the site stores an opaque session id bound to **this site's origin**. Another published site on the same EGDesk cannot reuse that session.
|
|
74
74
|
|
|
75
|
-
Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs
|
|
75
|
+
Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs**:
|
|
76
|
+
|
|
77
|
+
- Local: `http://localhost:54321/auth/callback`
|
|
78
|
+
- Tunnel: `https://tunneling-service.onrender.com/t/{tunnelId}/visitor-auth/callback` or `https://tunneling-service.onrender.com/**`
|
|
79
|
+
|
|
80
|
+
Do not add `?vid=` — extra query params make Supabase fall back to the Site URL (`egdesk.cloud`).
|
|
76
81
|
|
|
77
82
|
Owner MCP (`startDriveAuthLogin`) is a separate credential on the EGDesk machine. Visitor login does not overwrite it.
|
|
78
83
|
|
|
@@ -95,7 +95,7 @@ const CALLBACK_PAGE = `'use client';
|
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
97
|
import { useEffect, useState } from 'react';
|
|
98
|
-
import { exchangeVisitorAuthCode } from '@/egdesk-visitor-google';
|
|
98
|
+
import { exchangeVisitorAuthCode, resolveVisitorAppPath } from '@/egdesk-visitor-google';
|
|
99
99
|
|
|
100
100
|
export default function VisitorAuthCallbackPage() {
|
|
101
101
|
const [message, setMessage] = useState('Finishing sign-in…');
|
|
@@ -110,7 +110,7 @@ export default function VisitorAuthCallbackPage() {
|
|
|
110
110
|
}
|
|
111
111
|
void exchangeVisitorAuthCode(code)
|
|
112
112
|
.then(() => {
|
|
113
|
-
const dest = next.startsWith('/') ? next : '/';
|
|
113
|
+
const dest = resolveVisitorAppPath(next.startsWith('/') ? next : '/');
|
|
114
114
|
window.location.replace(dest);
|
|
115
115
|
})
|
|
116
116
|
.catch((err: unknown) => {
|
|
@@ -181,6 +181,43 @@ function visitorOriginHeaders(): Record<string, string> {
|
|
|
181
181
|
return { 'X-Visitor-Origin': window.location.origin };
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/** Tunnel production apps live under /t/{id}/p/{project}. Bare /auth/callback 404s. */
|
|
185
|
+
export function getVisitorSiteBasePath(): string {
|
|
186
|
+
const fromEnv =
|
|
187
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_BASE_PATH) || '';
|
|
188
|
+
if (fromEnv) return fromEnv.replace(/\\/$/, '');
|
|
189
|
+
if (typeof window === 'undefined') return '';
|
|
190
|
+
const parts = window.location.pathname.split('/').filter(Boolean);
|
|
191
|
+
if (parts[0] === 't' && parts.length >= 4 && parts[2] === 'p') {
|
|
192
|
+
return '/' + parts.slice(0, 4).join('/');
|
|
193
|
+
}
|
|
194
|
+
return '';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function resolveVisitorAppPath(path: string): string {
|
|
198
|
+
const base = getVisitorSiteBasePath();
|
|
199
|
+
const normalized = path.startsWith('/') ? path : '/' + path;
|
|
200
|
+
if (!base) return normalized;
|
|
201
|
+
if (normalized === base || normalized.startsWith(base + '/')) return normalized;
|
|
202
|
+
return base + normalized;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** MCP root for the public tunnel, e.g. https://tunneling-service.onrender.com/t/{id} */
|
|
206
|
+
export function resolveEgdeskPublicUrl(): string {
|
|
207
|
+
const configured =
|
|
208
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
209
|
+
'http://localhost:8080';
|
|
210
|
+
if (typeof window === 'undefined') return configured;
|
|
211
|
+
const parts = window.location.pathname.split('/').filter(Boolean);
|
|
212
|
+
const onTunnelGateway =
|
|
213
|
+
window.location.hostname === 'tunneling-service.onrender.com' ||
|
|
214
|
+
window.location.hostname.endsWith('.egdesk.cloud');
|
|
215
|
+
if (onTunnelGateway && parts[0] === 't' && parts[1]) {
|
|
216
|
+
return window.location.origin + '/t/' + parts[1];
|
|
217
|
+
}
|
|
218
|
+
return configured;
|
|
219
|
+
}
|
|
220
|
+
|
|
184
221
|
async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
|
|
185
222
|
const response = await apiFetch('/__visitor_auth_proxy', {
|
|
186
223
|
method: 'POST',
|
|
@@ -218,17 +255,18 @@ export async function startVisitorGoogleLogin(options: {
|
|
|
218
255
|
if (typeof window === 'undefined') {
|
|
219
256
|
throw new Error('startVisitorGoogleLogin() must run in the browser');
|
|
220
257
|
}
|
|
221
|
-
const next =
|
|
222
|
-
options.next && options.next.startsWith('/') ? options.next : window.location.pathname
|
|
223
|
-
|
|
258
|
+
const next = resolveVisitorAppPath(
|
|
259
|
+
options.next && options.next.startsWith('/') ? options.next : window.location.pathname,
|
|
260
|
+
);
|
|
261
|
+
const returnTo = new URL(resolveVisitorAppPath('/auth/callback'), window.location.origin);
|
|
224
262
|
returnTo.searchParams.set('next', next);
|
|
225
|
-
|
|
226
|
-
|
|
263
|
+
// Localhost → EGDesk :54321. Tunnel site → {gateway}/t/{id}/visitor-auth/callback.
|
|
264
|
+
const egdeskPublicUrl = resolveEgdeskPublicUrl();
|
|
227
265
|
|
|
228
266
|
const result = await callVisitorAuth('start', {
|
|
229
267
|
returnTo: returnTo.toString(),
|
|
230
268
|
egdeskPublicUrl,
|
|
231
|
-
forceConsent: options.forceConsent
|
|
269
|
+
forceConsent: options.forceConsent === true,
|
|
232
270
|
});
|
|
233
271
|
if (!result?.authUrl) {
|
|
234
272
|
throw new Error(result?.error || 'Failed to start visitor Google login');
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
9
9
|
* The app checks this at setup time and warns on mismatch.
|
|
10
10
|
*/
|
|
11
|
-
export declare const COMPATIBLE_APP_VERSION = "1.4.
|
|
11
|
+
export declare const COMPATIBLE_APP_VERSION = "1.4.59";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ exports.setupNextApiPlugin = setupNextApiPlugin;
|
|
|
46
46
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
47
47
|
* The app checks this at setup time and warns on mismatch.
|
|
48
48
|
*/
|
|
49
|
-
exports.COMPATIBLE_APP_VERSION = '1.4.
|
|
49
|
+
exports.COMPATIBLE_APP_VERSION = '1.4.59';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|