zitejs 0.9.91 → 0.9.92

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.
@@ -42,9 +42,17 @@ function loginWithRedirect(opts) {
42
42
  // any non-ASCII in the path fails its regex and the destination is dropped —
43
43
  // but never inspects the path of an absolute one. Normalising here means a
44
44
  // caller can pass whichever form reads best without having to know that.
45
- const redirectUrl = new URL(opts?.redirectUrl ?? window.location.href, window.location.href).toString();
46
- window.location.href =
47
- '/auth/login?' + new URLSearchParams({ redirectUrl }).toString();
45
+ const target = new URL(opts?.redirectUrl ?? window.location.href, window.location.href);
46
+ // Say nothing when there's nothing to say. The sign-in page already returns
47
+ // people to the app root when it isn't told otherwise, so naming the root
48
+ // spells out the default — and puts an encoded copy of the app's own URL in
49
+ // the address bar of every logged-out visitor to the front page, which is the
50
+ // common case. Only pass a destination when it IS one.
51
+ const isRoot = target.pathname === '/' && target.search === '' && target.hash === '';
52
+ window.location.href = isRoot
53
+ ? '/auth/login'
54
+ : '/auth/login?' +
55
+ new URLSearchParams({ redirectUrl: target.toString() }).toString();
48
56
  }
49
57
  function logout(opts) {
50
58
  (0, exports.signOut)().then(() => {
@@ -83,6 +83,24 @@ function redirectParamOf(href) {
83
83
  });
84
84
  });
85
85
  (0, vitest_1.describe)('loginWithRedirect', () => {
86
+ (0, vitest_1.it)('says nothing when the destination is the app root', () => {
87
+ // The sign-in page already returns people to the root, so naming it would
88
+ // just put an encoded copy of the app's own URL in the address bar — and a
89
+ // logged-out visitor to the front page is the common case.
90
+ const location = stubLocation('https://app.zite.so/');
91
+ authExports.loginWithRedirect();
92
+ (0, vitest_1.expect)(location.href).toBe('/auth/login');
93
+ });
94
+ (0, vitest_1.it)('says nothing when an explicit redirectUrl is the app root', () => {
95
+ const location = stubLocation('https://app.zite.so/pricing');
96
+ authExports.loginWithRedirect({ redirectUrl: '/' });
97
+ (0, vitest_1.expect)(location.href).toBe('/auth/login');
98
+ });
99
+ (0, vitest_1.it)('still names a root path that carries a query or hash', () => {
100
+ const location = stubLocation('https://app.zite.so/?invite=abc');
101
+ authExports.loginWithRedirect();
102
+ (0, vitest_1.expect)(redirectParamOf(location.href)).toBe('https://app.zite.so/?invite=abc');
103
+ });
86
104
  (0, vitest_1.it)('captures the current URL when called with no arguments', () => {
87
105
  const location = stubLocation('https://app.zite.so/orders/123?tab=open');
88
106
  authExports.loginWithRedirect();
@@ -35,9 +35,17 @@ export function loginWithRedirect(opts) {
35
35
  // any non-ASCII in the path fails its regex and the destination is dropped —
36
36
  // but never inspects the path of an absolute one. Normalising here means a
37
37
  // caller can pass whichever form reads best without having to know that.
38
- const redirectUrl = new URL(opts?.redirectUrl ?? window.location.href, window.location.href).toString();
39
- window.location.href =
40
- '/auth/login?' + new URLSearchParams({ redirectUrl }).toString();
38
+ const target = new URL(opts?.redirectUrl ?? window.location.href, window.location.href);
39
+ // Say nothing when there's nothing to say. The sign-in page already returns
40
+ // people to the app root when it isn't told otherwise, so naming the root
41
+ // spells out the default — and puts an encoded copy of the app's own URL in
42
+ // the address bar of every logged-out visitor to the front page, which is the
43
+ // common case. Only pass a destination when it IS one.
44
+ const isRoot = target.pathname === '/' && target.search === '' && target.hash === '';
45
+ window.location.href = isRoot
46
+ ? '/auth/login'
47
+ : '/auth/login?' +
48
+ new URLSearchParams({ redirectUrl: target.toString() }).toString();
41
49
  }
42
50
  export function logout(opts) {
43
51
  signOut().then(() => {
@@ -48,6 +48,24 @@ describe('zitejs/auth exports', () => {
48
48
  });
49
49
  });
50
50
  describe('loginWithRedirect', () => {
51
+ it('says nothing when the destination is the app root', () => {
52
+ // The sign-in page already returns people to the root, so naming it would
53
+ // just put an encoded copy of the app's own URL in the address bar — and a
54
+ // logged-out visitor to the front page is the common case.
55
+ const location = stubLocation('https://app.zite.so/');
56
+ authExports.loginWithRedirect();
57
+ expect(location.href).toBe('/auth/login');
58
+ });
59
+ it('says nothing when an explicit redirectUrl is the app root', () => {
60
+ const location = stubLocation('https://app.zite.so/pricing');
61
+ authExports.loginWithRedirect({ redirectUrl: '/' });
62
+ expect(location.href).toBe('/auth/login');
63
+ });
64
+ it('still names a root path that carries a query or hash', () => {
65
+ const location = stubLocation('https://app.zite.so/?invite=abc');
66
+ authExports.loginWithRedirect();
67
+ expect(redirectParamOf(location.href)).toBe('https://app.zite.so/?invite=abc');
68
+ });
51
69
  it('captures the current URL when called with no arguments', () => {
52
70
  const location = stubLocation('https://app.zite.so/orders/123?tab=open');
53
71
  authExports.loginWithRedirect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.91",
3
+ "version": "0.9.92",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",