zitejs 0.10.0-start.20 → 0.10.0-start.21
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/actions.d.ts +28 -0
- package/dist/cjs/auth/actions.js +93 -0
- package/dist/cjs/auth/client.d.ts +357 -0
- package/dist/cjs/auth/client.js +66 -0
- package/dist/cjs/auth/index.d.ts +2 -249
- package/dist/cjs/auth/index.js +11 -114
- package/dist/cjs/auth/index.test.js +18 -0
- package/dist/cjs/auth/profileUpdates.d.ts +9 -0
- package/dist/cjs/auth/profileUpdates.js +11 -0
- package/dist/cjs/check/start/sourceRules.js +70 -21
- package/dist/cjs/integrations/rules.js +5 -3
- package/dist/cjs/runtime/index.d.ts +54 -15
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +33 -0
- package/dist/cjs/sync/lib.js +10 -5
- package/dist/cjs/sync/lib.test.js +10 -0
- package/dist/esm/auth/actions.d.ts +28 -0
- package/dist/esm/auth/actions.js +55 -0
- package/dist/esm/auth/client.d.ts +357 -0
- package/dist/esm/auth/client.js +62 -0
- package/dist/esm/auth/index.d.ts +2 -249
- package/dist/esm/auth/index.js +2 -109
- package/dist/esm/auth/index.test.js +18 -0
- package/dist/esm/auth/profileUpdates.d.ts +9 -0
- package/dist/esm/auth/profileUpdates.js +6 -0
- package/dist/esm/check/start/sourceRules.js +70 -21
- package/dist/esm/integrations/rules.js +5 -3
- package/dist/esm/runtime/index.d.ts +54 -15
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +31 -0
- package/dist/esm/start/airtable/dispatch.js +3 -3
- package/dist/esm/start/airtable/formulas.d.ts +1 -1
- package/dist/esm/start/airtable/formulas.js +12 -10
- package/dist/esm/start/airtable/index.d.ts +2 -2
- package/dist/esm/start/describe.d.ts +8 -1
- package/dist/esm/start/describe.js +5 -3
- package/dist/esm/start/factories.test-d.d.ts +2 -1
- package/dist/esm/start/host.d.ts +2 -2
- package/dist/esm/start/index.d.ts +1 -1
- package/dist/esm/start/index.js +4 -2
- package/dist/esm/start/outbound.d.ts +2 -2
- package/dist/esm/start/outbound.js +3 -1
- package/dist/esm/start/router.d.ts +7 -0
- package/dist/esm/start/router.js +35 -0
- package/dist/esm/start/runLog.d.ts +2 -2
- package/dist/esm/start/scope.d.ts +3 -3
- package/dist/esm/start/server.d.ts +3 -3
- package/dist/esm/start/server.js +2 -1
- package/dist/esm/start/types.d.ts +1 -1
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/start/vite.js +3 -3
- package/dist/esm/start/workflow.d.ts +6 -2
- package/dist/esm/start/workflow.js +9 -2
- package/dist/esm/start/workflow.test-d.js +10 -1
- package/dist/esm/start/workflowRun.d.ts +5 -0
- package/dist/esm/start/workflowRun.js +11 -1
- package/dist/esm/sync/lib.js +10 -5
- package/dist/esm/sync/lib.test.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { createAuthClient } from 'better-auth/react';
|
|
3
|
+
import { magicLinkClient, inferAdditionalFields, } from 'better-auth/client/plugins';
|
|
4
|
+
import { getAccessMode } from './config.js';
|
|
5
|
+
import { loginWithRedirect, logout } from './actions.js';
|
|
6
|
+
// Apart from the actions, so an app that never reads the session here (a Start
|
|
7
|
+
// app reads its user from the router) never ships better-auth's client.
|
|
8
|
+
export const authClient = createAuthClient({
|
|
9
|
+
baseURL: '',
|
|
10
|
+
plugins: [
|
|
11
|
+
magicLinkClient(),
|
|
12
|
+
inferAdditionalFields({
|
|
13
|
+
user: {
|
|
14
|
+
firstName: { type: 'string', required: false },
|
|
15
|
+
lastName: { type: 'string', required: false },
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
export const useSession = authClient.useSession;
|
|
21
|
+
/**
|
|
22
|
+
* An internal app has no signed-out state — SSO runs before the bundle — so an
|
|
23
|
+
* empty session means it died underneath the app. Only `internal`: elsewhere a
|
|
24
|
+
* signed-out visitor is legitimate.
|
|
25
|
+
*/
|
|
26
|
+
function shouldRedirectSignedOut(isPending, hasUser) {
|
|
27
|
+
if (isPending || hasUser)
|
|
28
|
+
return false;
|
|
29
|
+
if (getAccessMode() !== 'internal')
|
|
30
|
+
return false;
|
|
31
|
+
if (typeof window === 'undefined')
|
|
32
|
+
return false;
|
|
33
|
+
// `loginWithRedirect` won't navigate from an auth page, so claiming a
|
|
34
|
+
// redirect here would hang `isLoading` forever.
|
|
35
|
+
return !window.location.pathname.startsWith('/auth/');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `loginWithRedirect` and `logout` are returned as well as exported. The
|
|
39
|
+
* pre-monorepo `useAuth()` returned them, so app code that destructures them
|
|
40
|
+
* from the hook is common — and returning them here means the legacy compat
|
|
41
|
+
* shim is the only thing that has to know that, not every migrated app.
|
|
42
|
+
*/
|
|
43
|
+
export function useAuth() {
|
|
44
|
+
const { data, isPending } = useSession();
|
|
45
|
+
const user = data?.user ?? null;
|
|
46
|
+
const redirecting = shouldRedirectSignedOut(isPending, user !== null);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (redirecting)
|
|
49
|
+
loginWithRedirect();
|
|
50
|
+
}, [redirecting]);
|
|
51
|
+
return {
|
|
52
|
+
user,
|
|
53
|
+
// Loading, not signed out: the signed-out branch is the empty screen this
|
|
54
|
+
// exists to prevent.
|
|
55
|
+
isLoading: isPending || redirecting,
|
|
56
|
+
loginWithRedirect,
|
|
57
|
+
logout,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export const signIn = authClient.signIn;
|
|
61
|
+
export const signOut = authClient.signOut;
|
|
62
|
+
export const signUp = authClient.signUp;
|
package/dist/esm/auth/index.d.ts
CHANGED
|
@@ -1,252 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
user: import("better-auth/react").StripEmptyObjects<{
|
|
4
|
-
id: string;
|
|
5
|
-
createdAt: Date;
|
|
6
|
-
updatedAt: Date;
|
|
7
|
-
email: string;
|
|
8
|
-
emailVerified: boolean;
|
|
9
|
-
name: string;
|
|
10
|
-
image?: string | null | undefined;
|
|
11
|
-
} & {} & {
|
|
12
|
-
firstName?: string | null | undefined;
|
|
13
|
-
lastName?: string | null | undefined;
|
|
14
|
-
}>;
|
|
15
|
-
session: import("better-auth/react").StripEmptyObjects<{
|
|
16
|
-
id: string;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
updatedAt: Date;
|
|
19
|
-
userId: string;
|
|
20
|
-
expiresAt: Date;
|
|
21
|
-
token: string;
|
|
22
|
-
ipAddress?: string | null | undefined;
|
|
23
|
-
userAgent?: string | null | undefined;
|
|
24
|
-
} & {} & {}>;
|
|
25
|
-
} | null;
|
|
26
|
-
isPending: boolean;
|
|
27
|
-
isRefetching: boolean;
|
|
28
|
-
error: import("@better-fetch/fetch").BetterFetchError | null;
|
|
29
|
-
refetch: (queryParams?: {
|
|
30
|
-
query?: import("better-auth").SessionQueryParams;
|
|
31
|
-
} | undefined) => Promise<void>;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* `loginWithRedirect` and `logout` are returned as well as exported. The
|
|
35
|
-
* pre-monorepo `useAuth()` returned them, so app code that destructures them
|
|
36
|
-
* from the hook is common — and returning them here means the legacy compat
|
|
37
|
-
* shim is the only thing that has to know that, not every migrated app.
|
|
38
|
-
*/
|
|
39
|
-
export declare function useAuth(): {
|
|
40
|
-
user: User | null;
|
|
41
|
-
isLoading: boolean;
|
|
42
|
-
loginWithRedirect: typeof loginWithRedirect;
|
|
43
|
-
logout: typeof logout;
|
|
44
|
-
};
|
|
45
|
-
export declare const signIn: {
|
|
46
|
-
magicLink: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
47
|
-
email: string;
|
|
48
|
-
name?: string | undefined;
|
|
49
|
-
callbackURL?: string | undefined;
|
|
50
|
-
newUserCallbackURL?: string | undefined;
|
|
51
|
-
errorCallbackURL?: string | undefined;
|
|
52
|
-
metadata?: Record<string, any> | undefined;
|
|
53
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
54
|
-
email: string;
|
|
55
|
-
name?: string | undefined;
|
|
56
|
-
callbackURL?: string | undefined;
|
|
57
|
-
newUserCallbackURL?: string | undefined;
|
|
58
|
-
errorCallbackURL?: string | undefined;
|
|
59
|
-
metadata?: Record<string, any> | undefined;
|
|
60
|
-
} & {
|
|
61
|
-
fetchOptions?: FetchOptions | undefined;
|
|
62
|
-
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
63
|
-
status: boolean;
|
|
64
|
-
}, {
|
|
65
|
-
code?: string | undefined;
|
|
66
|
-
message?: string | undefined;
|
|
67
|
-
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
68
|
-
} & {
|
|
69
|
-
social: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
70
|
-
provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | "line" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
|
|
71
|
-
callbackURL?: string | undefined;
|
|
72
|
-
newUserCallbackURL?: string | undefined;
|
|
73
|
-
errorCallbackURL?: string | undefined;
|
|
74
|
-
disableRedirect?: boolean | undefined;
|
|
75
|
-
idToken?: {
|
|
76
|
-
token: string;
|
|
77
|
-
nonce?: string | undefined;
|
|
78
|
-
accessToken?: string | undefined;
|
|
79
|
-
refreshToken?: string | undefined;
|
|
80
|
-
expiresAt?: number | undefined;
|
|
81
|
-
user?: {
|
|
82
|
-
name?: {
|
|
83
|
-
firstName?: string | undefined;
|
|
84
|
-
lastName?: string | undefined;
|
|
85
|
-
} | undefined;
|
|
86
|
-
email?: string | undefined;
|
|
87
|
-
} | undefined;
|
|
88
|
-
} | undefined;
|
|
89
|
-
scopes?: string[] | undefined;
|
|
90
|
-
requestSignUp?: boolean | undefined;
|
|
91
|
-
loginHint?: string | undefined;
|
|
92
|
-
additionalData?: Record<string, any> | undefined;
|
|
93
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
94
|
-
provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | "line" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
|
|
95
|
-
callbackURL?: string | undefined;
|
|
96
|
-
newUserCallbackURL?: string | undefined;
|
|
97
|
-
errorCallbackURL?: string | undefined;
|
|
98
|
-
disableRedirect?: boolean | undefined;
|
|
99
|
-
idToken?: {
|
|
100
|
-
token: string;
|
|
101
|
-
nonce?: string | undefined;
|
|
102
|
-
accessToken?: string | undefined;
|
|
103
|
-
refreshToken?: string | undefined;
|
|
104
|
-
expiresAt?: number | undefined;
|
|
105
|
-
user?: {
|
|
106
|
-
name?: {
|
|
107
|
-
firstName?: string | undefined;
|
|
108
|
-
lastName?: string | undefined;
|
|
109
|
-
} | undefined;
|
|
110
|
-
email?: string | undefined;
|
|
111
|
-
} | undefined;
|
|
112
|
-
} | undefined;
|
|
113
|
-
scopes?: string[] | undefined;
|
|
114
|
-
requestSignUp?: boolean | undefined;
|
|
115
|
-
loginHint?: string | undefined;
|
|
116
|
-
additionalData?: Record<string, any> | undefined;
|
|
117
|
-
} & {
|
|
118
|
-
fetchOptions?: FetchOptions | undefined;
|
|
119
|
-
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
120
|
-
redirect: boolean;
|
|
121
|
-
url: string;
|
|
122
|
-
} | (Omit<{
|
|
123
|
-
redirect: boolean;
|
|
124
|
-
token: string;
|
|
125
|
-
url: undefined;
|
|
126
|
-
user: {
|
|
127
|
-
id: string;
|
|
128
|
-
createdAt: Date;
|
|
129
|
-
updatedAt: Date;
|
|
130
|
-
email: string;
|
|
131
|
-
emailVerified: boolean;
|
|
132
|
-
name: string;
|
|
133
|
-
image?: string | null | undefined | undefined;
|
|
134
|
-
};
|
|
135
|
-
}, "user"> & {
|
|
136
|
-
user: import("better-auth/react").StripEmptyObjects<{
|
|
137
|
-
id: string;
|
|
138
|
-
createdAt: Date;
|
|
139
|
-
updatedAt: Date;
|
|
140
|
-
email: string;
|
|
141
|
-
emailVerified: boolean;
|
|
142
|
-
name: string;
|
|
143
|
-
image?: string | null | undefined;
|
|
144
|
-
} & {} & {
|
|
145
|
-
firstName?: string | null | undefined;
|
|
146
|
-
lastName?: string | null | undefined;
|
|
147
|
-
}>;
|
|
148
|
-
}), {
|
|
149
|
-
code?: string | undefined;
|
|
150
|
-
message?: string | undefined;
|
|
151
|
-
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
152
|
-
} & {
|
|
153
|
-
email: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
|
|
154
|
-
email: string;
|
|
155
|
-
password: string;
|
|
156
|
-
callbackURL?: string | undefined;
|
|
157
|
-
rememberMe?: boolean | undefined;
|
|
158
|
-
}> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
|
|
159
|
-
email: string;
|
|
160
|
-
password: string;
|
|
161
|
-
callbackURL?: string | undefined;
|
|
162
|
-
rememberMe?: boolean | undefined;
|
|
163
|
-
} & {
|
|
164
|
-
fetchOptions?: FetchOptions | undefined;
|
|
165
|
-
}>, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<Omit<{
|
|
166
|
-
redirect: boolean;
|
|
167
|
-
token: string;
|
|
168
|
-
url?: string | undefined;
|
|
169
|
-
user: {
|
|
170
|
-
id: string;
|
|
171
|
-
createdAt: Date;
|
|
172
|
-
updatedAt: Date;
|
|
173
|
-
email: string;
|
|
174
|
-
emailVerified: boolean;
|
|
175
|
-
name: string;
|
|
176
|
-
image?: string | null | undefined | undefined;
|
|
177
|
-
};
|
|
178
|
-
}, "user"> & {
|
|
179
|
-
user: import("better-auth/react").StripEmptyObjects<{
|
|
180
|
-
id: string;
|
|
181
|
-
createdAt: Date;
|
|
182
|
-
updatedAt: Date;
|
|
183
|
-
email: string;
|
|
184
|
-
emailVerified: boolean;
|
|
185
|
-
name: string;
|
|
186
|
-
image?: string | null | undefined;
|
|
187
|
-
} & {} & {
|
|
188
|
-
firstName?: string | null | undefined;
|
|
189
|
-
lastName?: string | null | undefined;
|
|
190
|
-
}>;
|
|
191
|
-
}, {
|
|
192
|
-
code?: string | undefined;
|
|
193
|
-
message?: string | undefined;
|
|
194
|
-
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
195
|
-
};
|
|
196
|
-
export declare const signOut: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth/react").Prettify<{
|
|
197
|
-
query?: Record<string, any> | undefined;
|
|
198
|
-
fetchOptions?: FetchOptions | undefined;
|
|
199
|
-
}> | undefined, data_1?: FetchOptions | undefined) => Promise<import("@better-fetch/fetch").BetterFetchResponse<{
|
|
200
|
-
success: boolean;
|
|
201
|
-
}, {
|
|
202
|
-
code?: string | undefined;
|
|
203
|
-
message?: string | undefined;
|
|
204
|
-
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
205
|
-
export declare const signUp: {
|
|
206
|
-
email: (data: {
|
|
207
|
-
email: string;
|
|
208
|
-
password: string;
|
|
209
|
-
name: string;
|
|
210
|
-
[key: string]: unknown;
|
|
211
|
-
}) => Promise<{
|
|
212
|
-
error?: {
|
|
213
|
-
message?: string;
|
|
214
|
-
} | null;
|
|
215
|
-
data?: unknown;
|
|
216
|
-
}>;
|
|
217
|
-
};
|
|
218
|
-
export declare function loginWithRedirect(opts?: {
|
|
219
|
-
redirectUrl?: string;
|
|
220
|
-
/**
|
|
221
|
-
* @deprecated Ignored. There is one sign-in screen now — the server works out
|
|
222
|
-
* from the email whether it's a sign-in or a sign-up. Still accepted, because
|
|
223
|
-
* app source written before that change would otherwise stop typechecking on
|
|
224
|
-
* its next build, and a typecheck error fails the build outright.
|
|
225
|
-
*/
|
|
226
|
-
initialView?: 'login' | 'signup';
|
|
227
|
-
}): void;
|
|
228
|
-
export declare function logout(opts?: {
|
|
229
|
-
returnTo?: string;
|
|
230
|
-
}): void;
|
|
231
|
-
export declare function updateProfile(data: {
|
|
232
|
-
name?: string;
|
|
233
|
-
firstName?: string;
|
|
234
|
-
lastName?: string;
|
|
235
|
-
image?: string;
|
|
236
|
-
}): Promise<{
|
|
237
|
-
data: {
|
|
238
|
-
status: boolean;
|
|
239
|
-
};
|
|
240
|
-
error: null;
|
|
241
|
-
} | {
|
|
242
|
-
data: null;
|
|
243
|
-
error: {
|
|
244
|
-
code?: string | undefined | undefined;
|
|
245
|
-
message?: string | undefined | undefined;
|
|
246
|
-
status: number;
|
|
247
|
-
statusText: string;
|
|
248
|
-
};
|
|
249
|
-
}>;
|
|
1
|
+
export { useSession, useAuth, signIn, signOut, signUp, } from './client.js';
|
|
2
|
+
export { loginWithRedirect, logout, updateProfile } from './actions.js';
|
|
250
3
|
/**
|
|
251
4
|
* An `interface`, not a type alias, so a migrated app can widen it by
|
|
252
5
|
* declaration merging (`.zite/user-extensions.d.ts`). A legacy user-sync app's
|
package/dist/esm/auth/index.js
CHANGED
|
@@ -1,109 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { magicLinkClient, inferAdditionalFields, } from 'better-auth/client/plugins';
|
|
4
|
-
import { USAGE_TOKEN_QUERY_PARAM } from './constants.js';
|
|
5
|
-
import { browserPreviewClaim, PREVIEW_CLAIM_PARAM } from './previewClaim.js';
|
|
6
|
-
import { getAccessMode } from './config.js';
|
|
7
|
-
const authClient = createAuthClient({
|
|
8
|
-
baseURL: '',
|
|
9
|
-
plugins: [
|
|
10
|
-
magicLinkClient(),
|
|
11
|
-
inferAdditionalFields({
|
|
12
|
-
user: {
|
|
13
|
-
firstName: { type: 'string', required: false },
|
|
14
|
-
lastName: { type: 'string', required: false },
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
17
|
-
],
|
|
18
|
-
});
|
|
19
|
-
export const useSession = authClient.useSession;
|
|
20
|
-
/**
|
|
21
|
-
* An internal app has no signed-out state — SSO runs before the bundle — so an
|
|
22
|
-
* empty session means it died underneath the app. Only `internal`: elsewhere a
|
|
23
|
-
* signed-out visitor is legitimate.
|
|
24
|
-
*/
|
|
25
|
-
function shouldRedirectSignedOut(isPending, hasUser) {
|
|
26
|
-
if (isPending || hasUser)
|
|
27
|
-
return false;
|
|
28
|
-
if (getAccessMode() !== 'internal')
|
|
29
|
-
return false;
|
|
30
|
-
if (typeof window === 'undefined')
|
|
31
|
-
return false;
|
|
32
|
-
// `loginWithRedirect` won't navigate from an auth page, so claiming a
|
|
33
|
-
// redirect here would hang `isLoading` forever.
|
|
34
|
-
return !window.location.pathname.startsWith('/auth/');
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* `loginWithRedirect` and `logout` are returned as well as exported. The
|
|
38
|
-
* pre-monorepo `useAuth()` returned them, so app code that destructures them
|
|
39
|
-
* from the hook is common — and returning them here means the legacy compat
|
|
40
|
-
* shim is the only thing that has to know that, not every migrated app.
|
|
41
|
-
*/
|
|
42
|
-
export function useAuth() {
|
|
43
|
-
const { data, isPending } = useSession();
|
|
44
|
-
const user = data?.user ?? null;
|
|
45
|
-
const redirecting = shouldRedirectSignedOut(isPending, user !== null);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (redirecting)
|
|
48
|
-
loginWithRedirect();
|
|
49
|
-
}, [redirecting]);
|
|
50
|
-
return {
|
|
51
|
-
user,
|
|
52
|
-
// Loading, not signed out: the signed-out branch is the empty screen this
|
|
53
|
-
// exists to prevent.
|
|
54
|
-
isLoading: isPending || redirecting,
|
|
55
|
-
loginWithRedirect,
|
|
56
|
-
logout,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export const signIn = authClient.signIn;
|
|
60
|
-
export const signOut = authClient.signOut;
|
|
61
|
-
export const signUp = authClient.signUp;
|
|
62
|
-
export function loginWithRedirect(opts) {
|
|
63
|
-
if (window.location.pathname.startsWith('/auth/'))
|
|
64
|
-
return;
|
|
65
|
-
// Default to wherever the user already is, so a deep link survives the round
|
|
66
|
-
// trip through login without every app having to remember to pass it. Pass
|
|
67
|
-
// `redirectUrl` only to send them somewhere else instead.
|
|
68
|
-
//
|
|
69
|
-
// Resolved to an absolute URL either way, on purpose: better-auth
|
|
70
|
-
// character-checks a *relative* callbackURL — an encoded space, a fragment or
|
|
71
|
-
// any non-ASCII in the path fails its regex and the destination is dropped —
|
|
72
|
-
// but never inspects the path of an absolute one. Normalising here means a
|
|
73
|
-
// caller can pass whichever form reads best without having to know that.
|
|
74
|
-
const target = new URL(opts?.redirectUrl ?? window.location.href, window.location.href);
|
|
75
|
-
// Say nothing when there's nothing to say. The sign-in page already returns
|
|
76
|
-
// people to the app root when it isn't told otherwise, so naming the root
|
|
77
|
-
// spells out the default — and puts an encoded copy of the app's own URL in
|
|
78
|
-
// the address bar of every logged-out visitor to the front page, which is the
|
|
79
|
-
// common case. Only pass a destination when it IS one.
|
|
80
|
-
const isRoot = target.pathname === '/' && target.search === '' && target.hash === '';
|
|
81
|
-
const params = new URLSearchParams();
|
|
82
|
-
if (!isRoot)
|
|
83
|
-
params.set('redirectUrl', target.toString());
|
|
84
|
-
// The editor preview rides its usageToken on the app URL; the sign-in page
|
|
85
|
-
// only shows its editor surface ("Preview as" picker) when that token reaches
|
|
86
|
-
// it. Capturing the current URL carries it implicitly — but an explicit
|
|
87
|
-
// `redirectUrl` names a bare path, and would silently drop it. Forward it
|
|
88
|
-
// top-level either way, so how the app phrases its redirect can't decide
|
|
89
|
-
// whether the editor gets a preview. Published visitors never have one.
|
|
90
|
-
const usageToken = new URL(window.location.href).searchParams.get(USAGE_TOKEN_QUERY_PARAM) ??
|
|
91
|
-
window._ziteUsageToken;
|
|
92
|
-
if (usageToken)
|
|
93
|
-
params.set(USAGE_TOKEN_QUERY_PARAM, usageToken);
|
|
94
|
-
// A Start app's preview also needs its claim where the editor's frame dropped
|
|
95
|
-
// the cookie, as `loginHref()` sends it. Classic previews never have one.
|
|
96
|
-
const claim = browserPreviewClaim();
|
|
97
|
-
if (claim)
|
|
98
|
-
params.set(PREVIEW_CLAIM_PARAM, claim);
|
|
99
|
-
const query = params.toString();
|
|
100
|
-
window.location.href = query ? `/auth/login?${query}` : '/auth/login';
|
|
101
|
-
}
|
|
102
|
-
export function logout(opts) {
|
|
103
|
-
signOut().then(() => {
|
|
104
|
-
window.location.href = opts?.returnTo || '/';
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
export function updateProfile(data) {
|
|
108
|
-
return authClient.updateUser(data);
|
|
109
|
-
}
|
|
1
|
+
export { useSession, useAuth, signIn, signOut, signUp, } from './client.js';
|
|
2
|
+
export { loginWithRedirect, logout, updateProfile } from './actions.js';
|
|
@@ -182,3 +182,21 @@ describe("the client's calls", () => {
|
|
|
182
182
|
]);
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
|
+
describe('a profile edit', () => {
|
|
186
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
187
|
+
it("tells a Start app's router once the platform saved it, and not when it refused", async () => {
|
|
188
|
+
let status = 400;
|
|
189
|
+
vi.stubGlobal('fetch', vi.fn(async () => Response.json(status === 200 ? { status: true } : { message: 'no' }, { status })));
|
|
190
|
+
// The client takes its fetch when the module loads.
|
|
191
|
+
vi.resetModules();
|
|
192
|
+
const { updateProfile } = await import('./index.js');
|
|
193
|
+
const { onProfileUpdated } = await import('./profileUpdates.js');
|
|
194
|
+
const told = vi.fn();
|
|
195
|
+
onProfileUpdated(told);
|
|
196
|
+
expect((await updateProfile({ firstName: 'Ada' })).error).not.toBeNull();
|
|
197
|
+
expect(told).not.toHaveBeenCalled();
|
|
198
|
+
status = 200;
|
|
199
|
+
expect((await updateProfile({ firstName: 'Ada' })).error).toBeNull();
|
|
200
|
+
expect(told).toHaveBeenCalledWith({ firstName: 'Ada' });
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ProfileChanges = {
|
|
2
|
+
name?: string;
|
|
3
|
+
firstName?: string;
|
|
4
|
+
lastName?: string;
|
|
5
|
+
image?: string;
|
|
6
|
+
};
|
|
7
|
+
/** @internal A Start app's router, in the browser, so a profile edit shows without a reload. */
|
|
8
|
+
export declare const onProfileUpdated: (next: (changes: ProfileChanges) => void) => void;
|
|
9
|
+
export declare const profileUpdated: (changes: ProfileChanges) => void;
|
|
@@ -441,6 +441,8 @@ const CLASSIC_IMPORTS = {
|
|
|
441
441
|
"react-router-dom": "routing is file routes, with Link and useNavigate from @tanstack/react-router",
|
|
442
442
|
"react-router": "routing is file routes, with Link and useNavigate from @tanstack/react-router",
|
|
443
443
|
};
|
|
444
|
+
// A Start app reads its user from the router; zitejs/auth's actions work in both runtimes.
|
|
445
|
+
const CLASSIC_AUTH_READS = new Set(["useAuth", "useSession"]);
|
|
444
446
|
const importsModule = (source, module) => source === module || source.startsWith(`${module}/`);
|
|
445
447
|
const containsTypeofWindow = (node) => {
|
|
446
448
|
let found = false;
|
|
@@ -659,11 +661,20 @@ const workflowProblems = (files, kind) => {
|
|
|
659
661
|
const { root, calls } = chainOf(init);
|
|
660
662
|
const innermost = calls.at(-1);
|
|
661
663
|
return root && file.imports.get(root)?.imported === "createAutomation" && innermost && nameOf(innermost.callee) === root
|
|
662
|
-
? innermost
|
|
664
|
+
? { call: innermost, finished: isHandlerCall(calls[0]) }
|
|
663
665
|
: undefined;
|
|
664
666
|
};
|
|
665
|
-
const workflow = (id, node, call) => {
|
|
667
|
+
const workflow = (id, node, call, finished) => {
|
|
666
668
|
exported.push({ id, file: file.path, node });
|
|
669
|
+
if (!finished) {
|
|
670
|
+
problems.push({
|
|
671
|
+
rule: "workflow-handler-missing",
|
|
672
|
+
severity: "error",
|
|
673
|
+
file: file.path,
|
|
674
|
+
...(lineOf(node) && { line: lineOf(node) }),
|
|
675
|
+
message: `automation ${id}: give createAutomation its function with .handler(async (args) => { ... }), not in its config`,
|
|
676
|
+
});
|
|
677
|
+
}
|
|
667
678
|
const config = resolveConst(file, call.arguments[0]);
|
|
668
679
|
const trigger = config?.type === "ObjectExpression" ? readProperty(file, config, "trigger") : undefined;
|
|
669
680
|
if (trigger?.type !== "ObjectExpression")
|
|
@@ -678,15 +689,26 @@ const workflowProblems = (files, kind) => {
|
|
|
678
689
|
});
|
|
679
690
|
return;
|
|
680
691
|
}
|
|
681
|
-
if (["every", "events"
|
|
692
|
+
if (["every", "events"].some((key) => readProperty(file, trigger, key) !== undefined))
|
|
682
693
|
return;
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
694
|
+
if (readProperty(file, trigger, "subscribe") === undefined) {
|
|
695
|
+
problems.push({
|
|
696
|
+
rule: "workflow-trigger-unregistered",
|
|
697
|
+
severity: "error",
|
|
698
|
+
file: file.path,
|
|
699
|
+
...(lineOf(node) && { line: lineOf(node) }),
|
|
700
|
+
message: `automation ${id}: a provider trigger needs \`subscribe\` to register it with the provider`,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
else if (readProperty(file, trigger, "unsubscribe") === undefined) {
|
|
704
|
+
problems.push({
|
|
705
|
+
rule: "workflow-trigger-unsubscribe-missing",
|
|
706
|
+
severity: "error",
|
|
707
|
+
file: file.path,
|
|
708
|
+
...(lineOf(node) && { line: lineOf(node) }),
|
|
709
|
+
message: `automation ${id}: a provider trigger needs \`unsubscribe\` too, or its registration outlives it`,
|
|
710
|
+
});
|
|
711
|
+
}
|
|
690
712
|
};
|
|
691
713
|
const locals = new Map();
|
|
692
714
|
for (const statement of file.program.body) {
|
|
@@ -694,13 +716,13 @@ const workflowProblems = (files, kind) => {
|
|
|
694
716
|
if (declaration?.type === "VariableDeclaration") {
|
|
695
717
|
for (const declarator of declaration.declarations) {
|
|
696
718
|
const name = nameOf(declarator.id);
|
|
697
|
-
const
|
|
698
|
-
if (!name || !
|
|
719
|
+
const created = createCall(declarator.init);
|
|
720
|
+
if (!name || !created)
|
|
699
721
|
continue;
|
|
700
722
|
if (statement.type === "ExportNamedDeclaration")
|
|
701
|
-
workflow(name, declarator, call);
|
|
723
|
+
workflow(name, declarator, created.call, created.finished);
|
|
702
724
|
else
|
|
703
|
-
locals.set(name, { node: declarator,
|
|
725
|
+
locals.set(name, { node: declarator, ...created });
|
|
704
726
|
}
|
|
705
727
|
}
|
|
706
728
|
if (statement.type === "ExportNamedDeclaration" && !statement.source) {
|
|
@@ -708,13 +730,13 @@ const workflowProblems = (files, kind) => {
|
|
|
708
730
|
const local = locals.get(nameOf(specifier.local) ?? "");
|
|
709
731
|
const id = nameOf(specifier.exported);
|
|
710
732
|
if (local && id)
|
|
711
|
-
workflow(id, specifier, local.call);
|
|
733
|
+
workflow(id, specifier, local.call, local.finished);
|
|
712
734
|
}
|
|
713
735
|
}
|
|
714
736
|
if (statement.type === "ExportDefaultDeclaration") {
|
|
715
737
|
const declared = statement.declaration;
|
|
716
|
-
const
|
|
717
|
-
if (
|
|
738
|
+
const created = createCall(declared) ?? (declared.type === "Identifier" ? locals.get(declared.name) : undefined);
|
|
739
|
+
if (created) {
|
|
718
740
|
problems.push({
|
|
719
741
|
rule: "workflow-default-export",
|
|
720
742
|
severity: "error",
|
|
@@ -762,7 +784,15 @@ const workflowProblems = (files, kind) => {
|
|
|
762
784
|
return problems;
|
|
763
785
|
};
|
|
764
786
|
// What the build keeps out of the browser (zite()'s importProtection), by the specifier an app writes.
|
|
765
|
-
const SERVER_ONLY_IMPORTS = [
|
|
787
|
+
const SERVER_ONLY_IMPORTS = [
|
|
788
|
+
/^zitejs\/db$/,
|
|
789
|
+
/^zitejs\/integrations(\/|$)/,
|
|
790
|
+
/^zitejs\/email$/,
|
|
791
|
+
/^zitejs\/meta$/,
|
|
792
|
+
/(^|\/)\.zite\/db(\.ts)?$/,
|
|
793
|
+
/(^|\/)\.zite\/integrations(\/|$)/,
|
|
794
|
+
/(^|\/)\.zite\/meta(\.ts)?$/,
|
|
795
|
+
];
|
|
766
796
|
const isServerOnlyFile = (path) => /\.server(\.[^/]*)?$/.test(path.split("/").pop() ?? "");
|
|
767
797
|
const SOURCE_EXTENSIONS = ["", ".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", "/index.ts", "/index.tsx", "/index.js"];
|
|
768
798
|
// As TypeScript and Vite read a .js specifier: the TypeScript file it compiles from.
|
|
@@ -846,14 +876,23 @@ const serverImportProblems = (files, factories, routerPath) => {
|
|
|
846
876
|
pageRoots.forEach(visit);
|
|
847
877
|
return problems;
|
|
848
878
|
};
|
|
849
|
-
const
|
|
879
|
+
const isCreateZiteRouter = (file, callee) => {
|
|
850
880
|
if (callee.type === "Identifier")
|
|
851
881
|
return (file.imports.get(callee.name)?.imported ?? callee.name) === "createZiteRouter";
|
|
852
882
|
const namespace = callee.type === "MemberExpression" && !callee.computed && nameOf(callee.property) === "createZiteRouter"
|
|
853
883
|
? file.imports.get(nameOf(callee.object) ?? "")
|
|
854
884
|
: undefined;
|
|
855
885
|
return namespace?.imported === "*" && namespace.source === "zitejs/start";
|
|
856
|
-
}
|
|
886
|
+
};
|
|
887
|
+
const createZiteRouterCalls = (file) => {
|
|
888
|
+
const calls = [];
|
|
889
|
+
walk(file.program, (node, ancestors) => {
|
|
890
|
+
if (node.type === "CallExpression" && isNode(node.callee) && isCreateZiteRouter(file, node.callee)) {
|
|
891
|
+
calls.push({ node, atModuleScope: atModuleScope(ancestors) });
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
return calls;
|
|
895
|
+
};
|
|
857
896
|
/** Every source hint for one Start app, given its files by app-relative path. */
|
|
858
897
|
export function sourceProblems(sources, { internal = false, kind } = {}) {
|
|
859
898
|
const files = Object.entries(sources)
|
|
@@ -869,7 +908,8 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
|
|
|
869
908
|
// As Start finds it. One that doesn't parse is the typecheck's to report.
|
|
870
909
|
const routerPath = ENTRY_EXTENSIONS.map((extension) => `src/router${extension}`).find((path) => sources[path] !== undefined);
|
|
871
910
|
const router = files.find((file) => file.path === routerPath);
|
|
872
|
-
|
|
911
|
+
const routerCalls = router ? createZiteRouterCalls(router) : [];
|
|
912
|
+
if (!routerPath || (router && routerCalls.length === 0)) {
|
|
873
913
|
problems.push({
|
|
874
914
|
rule: "router-file",
|
|
875
915
|
severity: "error",
|
|
@@ -877,6 +917,10 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
|
|
|
877
917
|
message: `export getRouter from ${routerPath ?? "src/router.tsx"}, built with createZiteRouter from zitejs/start, which gives pages the signed-in user`,
|
|
878
918
|
});
|
|
879
919
|
}
|
|
920
|
+
const shared = routerCalls.find((call) => call.atModuleScope);
|
|
921
|
+
if (routerPath && shared) {
|
|
922
|
+
report("router-file", "error", routerPath, shared.node, `${routerPath} builds one router for every visitor, which shows each the first one's user and data; call createZiteRouter inside getRouter`);
|
|
923
|
+
}
|
|
880
924
|
for (const file of files) {
|
|
881
925
|
const { path, program } = file;
|
|
882
926
|
const callsWorkflow = callsCreateWorkflow(program);
|
|
@@ -911,6 +955,11 @@ export function sourceProblems(sources, { internal = false, kind } = {}) {
|
|
|
911
955
|
report("classic-construct", "error", path, statement, `${module} is classic's; in a Start app, ${instead}`);
|
|
912
956
|
}
|
|
913
957
|
}
|
|
958
|
+
if (source === "zitejs/auth" && values !== "all") {
|
|
959
|
+
for (const name of values.filter((imported) => CLASSIC_AUTH_READS.has(imported))) {
|
|
960
|
+
report("classic-construct", "error", path, statement, `${name} is classic's; in a Start app, read the user from the router: context.user in beforeLoad and loaders, Route.useRouteContext() in a page, useRouteContext({ from: '__root__' }) in shared components`);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
914
963
|
if (source === "cloudflare:workers") {
|
|
915
964
|
report("cloudflare-env", "error", path, statement, "read the app's environment from process.env, not cloudflare:workers");
|
|
916
965
|
}
|
|
@@ -72,8 +72,8 @@ const FIELDS_BY_TYPE = {
|
|
|
72
72
|
// one host to call.
|
|
73
73
|
pipedrive: extras("apiBaseUrl"),
|
|
74
74
|
// Shopify has no global API host: every call goes to the store's own domain
|
|
75
|
-
// under a pinned API version. The storefront pair is the shopper-facing API
|
|
76
|
-
//
|
|
75
|
+
// under a pinned API version. The storefront pair is the shopper-facing API;
|
|
76
|
+
// its URL comes from the store domain, so only the token can be missing.
|
|
77
77
|
shopify: extras("shopDomain", "apiBaseUrl", "storefrontApiUrl", "storefrontAccessToken"),
|
|
78
78
|
sharepoint: extras(),
|
|
79
79
|
excel: extras(),
|
|
@@ -93,7 +93,9 @@ export const OPTIONAL_CREDENTIAL_FIELDS = {
|
|
|
93
93
|
// Only S3-compatible providers set an endpoint, and a prefix is opt-in.
|
|
94
94
|
amazonS3: ["endpoint", "pathPrefix"],
|
|
95
95
|
snowflake: ["warehouse"],
|
|
96
|
-
|
|
96
|
+
// A store that didn't grant the storefront scopes gets no token, and
|
|
97
|
+
// Shopify then serves the Storefront API tokenless.
|
|
98
|
+
shopify: ["storefrontAccessToken"],
|
|
97
99
|
};
|
|
98
100
|
/**
|
|
99
101
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|