zitejs 0.9.104 → 0.9.105
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/dist/cjs/auth/index.js +16 -4
- package/dist/cjs/auth/index.test.js +39 -0
- package/dist/esm/auth/index.js +16 -4
- package/dist/esm/auth/index.test.js +39 -0
- package/dist/esm/cli.js +0 -0
- package/package.json +1 -1
- package/dist/cjs/api/index.js +0 -5
- package/dist/cjs/db/index.js +0 -5
- package/dist/esm/api/index.d.ts +0 -2
- package/dist/esm/api/index.js +0 -1
- package/dist/esm/db/index.d.ts +0 -2
- package/dist/esm/db/index.js +0 -1
package/dist/cjs/auth/index.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.logout = logout;
|
|
|
7
7
|
exports.updateProfile = updateProfile;
|
|
8
8
|
const react_1 = require("better-auth/react");
|
|
9
9
|
const plugins_1 = require("better-auth/client/plugins");
|
|
10
|
+
const constants_js_1 = require("./constants.js");
|
|
10
11
|
const authClient = (0, react_1.createAuthClient)({
|
|
11
12
|
baseURL: '',
|
|
12
13
|
plugins: [
|
|
@@ -57,10 +58,21 @@ function loginWithRedirect(opts) {
|
|
|
57
58
|
// the address bar of every logged-out visitor to the front page, which is the
|
|
58
59
|
// common case. Only pass a destination when it IS one.
|
|
59
60
|
const isRoot = target.pathname === '/' && target.search === '' && target.hash === '';
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const params = new URLSearchParams();
|
|
62
|
+
if (!isRoot)
|
|
63
|
+
params.set('redirectUrl', target.toString());
|
|
64
|
+
// The editor preview rides its usageToken on the app URL; the sign-in page
|
|
65
|
+
// only shows its editor surface ("Preview as" picker) when that token reaches
|
|
66
|
+
// it. Capturing the current URL carries it implicitly — but an explicit
|
|
67
|
+
// `redirectUrl` names a bare path, and would silently drop it. Forward it
|
|
68
|
+
// top-level either way, so how the app phrases its redirect can't decide
|
|
69
|
+
// whether the editor gets a preview. Published visitors never have one.
|
|
70
|
+
const usageToken = new URL(window.location.href).searchParams.get(constants_js_1.USAGE_TOKEN_QUERY_PARAM) ??
|
|
71
|
+
window._ziteUsageToken;
|
|
72
|
+
if (usageToken)
|
|
73
|
+
params.set(constants_js_1.USAGE_TOKEN_QUERY_PARAM, usageToken);
|
|
74
|
+
const query = params.toString();
|
|
75
|
+
window.location.href = query ? `/auth/login?${query}` : '/auth/login';
|
|
64
76
|
}
|
|
65
77
|
function logout(opts) {
|
|
66
78
|
(0, exports.signOut)().then(() => {
|
|
@@ -147,4 +147,43 @@ function redirectParamOf(href) {
|
|
|
147
147
|
(0, vitest_1.expect)(params.get('view')).toBeNull();
|
|
148
148
|
(0, vitest_1.expect)(params.get('redirectUrl')).toBe('https://app.zite.so/pricing');
|
|
149
149
|
});
|
|
150
|
+
(0, vitest_1.it)('forwards the editor usageToken past an explicit redirectUrl', () => {
|
|
151
|
+
// The editor preview rides its token on the app URL. An explicit
|
|
152
|
+
// redirectUrl names a bare path, which used to silently drop it — and with
|
|
153
|
+
// it the sign-in page's whole editor surface ("Preview as" picker).
|
|
154
|
+
const location = stubLocation('https://app.zite.so/?usageToken=tok-123');
|
|
155
|
+
authExports.loginWithRedirect({ redirectUrl: '/dashboard' });
|
|
156
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
157
|
+
(0, vitest_1.expect)(params.get('usageToken')).toBe('tok-123');
|
|
158
|
+
(0, vitest_1.expect)(params.get('redirectUrl')).toBe('https://app.zite.so/dashboard');
|
|
159
|
+
});
|
|
160
|
+
(0, vitest_1.it)('forwards the usageToken top-level on a bare call too', () => {
|
|
161
|
+
const location = stubLocation('https://app.zite.so/orders/123?usageToken=tok-123');
|
|
162
|
+
authExports.loginWithRedirect();
|
|
163
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
164
|
+
(0, vitest_1.expect)(params.get('usageToken')).toBe('tok-123');
|
|
165
|
+
});
|
|
166
|
+
(0, vitest_1.it)('carries a token to a root destination that would otherwise say nothing', () => {
|
|
167
|
+
const location = stubLocation('https://app.zite.so/?usageToken=tok-123');
|
|
168
|
+
// The token is the whole search string here only if nothing else rides
|
|
169
|
+
// along — an explicit root override drops the query, exercising the
|
|
170
|
+
// token-only branch.
|
|
171
|
+
authExports.loginWithRedirect({ redirectUrl: '/' });
|
|
172
|
+
(0, vitest_1.expect)(location.href).toBe('/auth/login?usageToken=tok-123');
|
|
173
|
+
});
|
|
174
|
+
(0, vitest_1.it)('falls back to window._ziteUsageToken when the URL was scrubbed', () => {
|
|
175
|
+
// app-runner's injected boot script moves the token off the address bar
|
|
176
|
+
// into this global before the bundle runs.
|
|
177
|
+
const location = stubLocation('https://app.zite.so/pricing');
|
|
178
|
+
window._ziteUsageToken = 'tok-456';
|
|
179
|
+
authExports.loginWithRedirect({ redirectUrl: '/dashboard' });
|
|
180
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
181
|
+
(0, vitest_1.expect)(params.get('usageToken')).toBe('tok-456');
|
|
182
|
+
});
|
|
183
|
+
(0, vitest_1.it)('adds no token param for ordinary visitors', () => {
|
|
184
|
+
const location = stubLocation('https://app.zite.so/pricing');
|
|
185
|
+
authExports.loginWithRedirect();
|
|
186
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
187
|
+
(0, vitest_1.expect)(params.get('usageToken')).toBeNull();
|
|
188
|
+
});
|
|
150
189
|
});
|
package/dist/esm/auth/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAuthClient } from 'better-auth/react';
|
|
2
2
|
import { magicLinkClient, inferAdditionalFields, } from 'better-auth/client/plugins';
|
|
3
|
+
import { USAGE_TOKEN_QUERY_PARAM } from './constants.js';
|
|
3
4
|
const authClient = createAuthClient({
|
|
4
5
|
baseURL: '',
|
|
5
6
|
plugins: [
|
|
@@ -50,10 +51,21 @@ export function loginWithRedirect(opts) {
|
|
|
50
51
|
// the address bar of every logged-out visitor to the front page, which is the
|
|
51
52
|
// common case. Only pass a destination when it IS one.
|
|
52
53
|
const isRoot = target.pathname === '/' && target.search === '' && target.hash === '';
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const params = new URLSearchParams();
|
|
55
|
+
if (!isRoot)
|
|
56
|
+
params.set('redirectUrl', target.toString());
|
|
57
|
+
// The editor preview rides its usageToken on the app URL; the sign-in page
|
|
58
|
+
// only shows its editor surface ("Preview as" picker) when that token reaches
|
|
59
|
+
// it. Capturing the current URL carries it implicitly — but an explicit
|
|
60
|
+
// `redirectUrl` names a bare path, and would silently drop it. Forward it
|
|
61
|
+
// top-level either way, so how the app phrases its redirect can't decide
|
|
62
|
+
// whether the editor gets a preview. Published visitors never have one.
|
|
63
|
+
const usageToken = new URL(window.location.href).searchParams.get(USAGE_TOKEN_QUERY_PARAM) ??
|
|
64
|
+
window._ziteUsageToken;
|
|
65
|
+
if (usageToken)
|
|
66
|
+
params.set(USAGE_TOKEN_QUERY_PARAM, usageToken);
|
|
67
|
+
const query = params.toString();
|
|
68
|
+
window.location.href = query ? `/auth/login?${query}` : '/auth/login';
|
|
57
69
|
}
|
|
58
70
|
export function logout(opts) {
|
|
59
71
|
signOut().then(() => {
|
|
@@ -112,4 +112,43 @@ describe('loginWithRedirect', () => {
|
|
|
112
112
|
expect(params.get('view')).toBeNull();
|
|
113
113
|
expect(params.get('redirectUrl')).toBe('https://app.zite.so/pricing');
|
|
114
114
|
});
|
|
115
|
+
it('forwards the editor usageToken past an explicit redirectUrl', () => {
|
|
116
|
+
// The editor preview rides its token on the app URL. An explicit
|
|
117
|
+
// redirectUrl names a bare path, which used to silently drop it — and with
|
|
118
|
+
// it the sign-in page's whole editor surface ("Preview as" picker).
|
|
119
|
+
const location = stubLocation('https://app.zite.so/?usageToken=tok-123');
|
|
120
|
+
authExports.loginWithRedirect({ redirectUrl: '/dashboard' });
|
|
121
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
122
|
+
expect(params.get('usageToken')).toBe('tok-123');
|
|
123
|
+
expect(params.get('redirectUrl')).toBe('https://app.zite.so/dashboard');
|
|
124
|
+
});
|
|
125
|
+
it('forwards the usageToken top-level on a bare call too', () => {
|
|
126
|
+
const location = stubLocation('https://app.zite.so/orders/123?usageToken=tok-123');
|
|
127
|
+
authExports.loginWithRedirect();
|
|
128
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
129
|
+
expect(params.get('usageToken')).toBe('tok-123');
|
|
130
|
+
});
|
|
131
|
+
it('carries a token to a root destination that would otherwise say nothing', () => {
|
|
132
|
+
const location = stubLocation('https://app.zite.so/?usageToken=tok-123');
|
|
133
|
+
// The token is the whole search string here only if nothing else rides
|
|
134
|
+
// along — an explicit root override drops the query, exercising the
|
|
135
|
+
// token-only branch.
|
|
136
|
+
authExports.loginWithRedirect({ redirectUrl: '/' });
|
|
137
|
+
expect(location.href).toBe('/auth/login?usageToken=tok-123');
|
|
138
|
+
});
|
|
139
|
+
it('falls back to window._ziteUsageToken when the URL was scrubbed', () => {
|
|
140
|
+
// app-runner's injected boot script moves the token off the address bar
|
|
141
|
+
// into this global before the bundle runs.
|
|
142
|
+
const location = stubLocation('https://app.zite.so/pricing');
|
|
143
|
+
window._ziteUsageToken = 'tok-456';
|
|
144
|
+
authExports.loginWithRedirect({ redirectUrl: '/dashboard' });
|
|
145
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
146
|
+
expect(params.get('usageToken')).toBe('tok-456');
|
|
147
|
+
});
|
|
148
|
+
it('adds no token param for ordinary visitors', () => {
|
|
149
|
+
const location = stubLocation('https://app.zite.so/pricing');
|
|
150
|
+
authExports.loginWithRedirect();
|
|
151
|
+
const params = new URLSearchParams(location.href.split('?')[1] ?? '');
|
|
152
|
+
expect(params.get('usageToken')).toBeNull();
|
|
153
|
+
});
|
|
115
154
|
});
|
package/dist/esm/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/dist/cjs/api/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCaller = void 0;
|
|
4
|
-
var index_js_1 = require("../caller/index.js");
|
|
5
|
-
Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
|
package/dist/cjs/db/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTableClient = void 0;
|
|
4
|
-
var index_js_1 = require("../runtime/index.js");
|
|
5
|
-
Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
|
package/dist/esm/api/index.d.ts
DELETED
package/dist/esm/api/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createCaller } from '../caller/index.js';
|
package/dist/esm/db/index.d.ts
DELETED
package/dist/esm/db/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createTableClient } from '../runtime/index.js';
|