@instroc/auth 1.3.1 → 2.0.0-alpha.2
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/chunk-26ODM5TP.js +958 -0
- package/dist/forms.d.ts +1 -1
- package/dist/forms.js +1 -1
- package/dist/{index-iglVgSQI.d.ts → index-BsFMnPty.d.ts} +1 -1
- package/dist/index.d.ts +36 -11
- package/dist/index.js +36 -2
- package/package.json +11 -10
- package/dist/chunk-4FR5RRCB.js +0 -1036
package/dist/chunk-4FR5RRCB.js
DELETED
|
@@ -1,1036 +0,0 @@
|
|
|
1
|
-
// src/forms/use-login-form.ts
|
|
2
|
-
import { useState as useState3, useCallback as useCallback2, useRef as useRef2, useEffect as useEffect3 } from "react";
|
|
3
|
-
|
|
4
|
-
// src/use-auth.ts
|
|
5
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
6
|
-
|
|
7
|
-
// src/provider.tsx
|
|
8
|
-
import {
|
|
9
|
-
createContext,
|
|
10
|
-
useContext,
|
|
11
|
-
useState,
|
|
12
|
-
useCallback,
|
|
13
|
-
useEffect,
|
|
14
|
-
useRef
|
|
15
|
-
} from "react";
|
|
16
|
-
|
|
17
|
-
// src/errors.ts
|
|
18
|
-
var AuthError = class _AuthError extends Error {
|
|
19
|
-
constructor(message, status, code) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = "AuthError";
|
|
22
|
-
this.status = status;
|
|
23
|
-
this.code = code;
|
|
24
|
-
Object.setPrototypeOf(this, _AuthError.prototype);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
function authErrorFromResponse(response, data, fallbackMessage) {
|
|
28
|
-
const body = data ?? {};
|
|
29
|
-
const message = body.error || fallbackMessage;
|
|
30
|
-
return new AuthError(message, response.status, body.code);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/version.ts
|
|
34
|
-
var SDK_NAME = "instroc-auth";
|
|
35
|
-
var SDK_VERSION = true ? "1.3.1" : "0.0.0-dev";
|
|
36
|
-
function withSdkHeader(init) {
|
|
37
|
-
const headers = new Headers(init?.headers ?? {});
|
|
38
|
-
headers.set("X-Instroc-SDK", `${SDK_NAME}/${SDK_VERSION}`);
|
|
39
|
-
return { ...init, headers };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/provider.tsx
|
|
43
|
-
import { jsx } from "react/jsx-runtime";
|
|
44
|
-
var AuthContext = createContext(null);
|
|
45
|
-
var STORAGE_KEY = "instroc_auth_session";
|
|
46
|
-
var WARNING_SESSION_KEY = "instroc_auth_sdk_warning_seen";
|
|
47
|
-
function noteDeprecationWarning(response) {
|
|
48
|
-
const warning = response.headers?.get?.("X-Instroc-SDK-Warning");
|
|
49
|
-
if (!warning)
|
|
50
|
-
return;
|
|
51
|
-
if (typeof window === "undefined")
|
|
52
|
-
return;
|
|
53
|
-
try {
|
|
54
|
-
if (sessionStorage.getItem(WARNING_SESSION_KEY))
|
|
55
|
-
return;
|
|
56
|
-
sessionStorage.setItem(WARNING_SESSION_KEY, "1");
|
|
57
|
-
} catch {
|
|
58
|
-
}
|
|
59
|
-
console.warn(`[instroc-auth] ${warning}`);
|
|
60
|
-
}
|
|
61
|
-
function AuthProvider({
|
|
62
|
-
children,
|
|
63
|
-
projectId: initialProjectId,
|
|
64
|
-
baseUrl = "/api/baas",
|
|
65
|
-
persistSession = true,
|
|
66
|
-
onAuthStateChange
|
|
67
|
-
}) {
|
|
68
|
-
const [projectId, setProjectId] = useState(
|
|
69
|
-
initialProjectId || null
|
|
70
|
-
);
|
|
71
|
-
const [user, setUser] = useState(null);
|
|
72
|
-
const [session, setSession] = useState(null);
|
|
73
|
-
const [loading, setLoading] = useState(true);
|
|
74
|
-
const [error, setError] = useState(null);
|
|
75
|
-
const [authConfig, setAuthConfig] = useState(null);
|
|
76
|
-
const [visibilityConfig, setVisibilityConfig] = useState(null);
|
|
77
|
-
const refreshTimeoutRef = useRef(null);
|
|
78
|
-
const buildUrl = useCallback(
|
|
79
|
-
(endpoint) => {
|
|
80
|
-
if (!projectId) {
|
|
81
|
-
throw new Error("Project ID is required");
|
|
82
|
-
}
|
|
83
|
-
return `${baseUrl}/${projectId}/auth/${endpoint}`;
|
|
84
|
-
},
|
|
85
|
-
[projectId, baseUrl]
|
|
86
|
-
);
|
|
87
|
-
const authFetch = useCallback(async (url, init) => {
|
|
88
|
-
const response = await fetch(url, {
|
|
89
|
-
...withSdkHeader(init),
|
|
90
|
-
credentials: "include"
|
|
91
|
-
});
|
|
92
|
-
noteDeprecationWarning(response);
|
|
93
|
-
return response;
|
|
94
|
-
}, []);
|
|
95
|
-
const saveSession = useCallback(
|
|
96
|
-
(sessionData) => {
|
|
97
|
-
if (persistSession && typeof window !== "undefined") {
|
|
98
|
-
if (sessionData) {
|
|
99
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(sessionData));
|
|
100
|
-
} else {
|
|
101
|
-
localStorage.removeItem(STORAGE_KEY);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
[persistSession]
|
|
106
|
-
);
|
|
107
|
-
const loadSession = useCallback(() => {
|
|
108
|
-
if (persistSession && typeof window !== "undefined") {
|
|
109
|
-
const stored = localStorage.getItem(STORAGE_KEY);
|
|
110
|
-
if (stored) {
|
|
111
|
-
try {
|
|
112
|
-
return JSON.parse(stored);
|
|
113
|
-
} catch {
|
|
114
|
-
localStorage.removeItem(STORAGE_KEY);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}, [persistSession]);
|
|
120
|
-
const scheduleRefresh = useCallback(
|
|
121
|
-
(expiresAt) => {
|
|
122
|
-
if (refreshTimeoutRef.current) {
|
|
123
|
-
clearTimeout(refreshTimeoutRef.current);
|
|
124
|
-
}
|
|
125
|
-
const expiresTime = new Date(expiresAt).getTime();
|
|
126
|
-
const now = Date.now();
|
|
127
|
-
const refreshIn = expiresTime - now - 5 * 60 * 1e3;
|
|
128
|
-
if (refreshIn > 0) {
|
|
129
|
-
refreshTimeoutRef.current = setTimeout(async () => {
|
|
130
|
-
try {
|
|
131
|
-
await refreshSession();
|
|
132
|
-
} catch (err) {
|
|
133
|
-
console.warn("Token refresh failed:", err);
|
|
134
|
-
setUser(null);
|
|
135
|
-
setSession(null);
|
|
136
|
-
saveSession(null);
|
|
137
|
-
}
|
|
138
|
-
}, refreshIn);
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
[saveSession]
|
|
142
|
-
);
|
|
143
|
-
const updateAuthState = useCallback(
|
|
144
|
-
(newUser, newSession) => {
|
|
145
|
-
setUser(newUser);
|
|
146
|
-
setSession(newSession);
|
|
147
|
-
saveSession(newSession);
|
|
148
|
-
if (newSession) {
|
|
149
|
-
scheduleRefresh(newSession.expires_at);
|
|
150
|
-
}
|
|
151
|
-
if (onAuthStateChange) {
|
|
152
|
-
onAuthStateChange(newUser);
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
[saveSession, scheduleRefresh, onAuthStateChange]
|
|
156
|
-
);
|
|
157
|
-
const fetchUser = useCallback(async () => {
|
|
158
|
-
const storedSession = loadSession();
|
|
159
|
-
if (!storedSession || !projectId) {
|
|
160
|
-
setLoading(false);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
const response = await authFetch(buildUrl("me"), {
|
|
165
|
-
headers: {
|
|
166
|
-
Authorization: `Bearer ${storedSession.access_token}`
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (response.ok) {
|
|
170
|
-
const data = await response.json();
|
|
171
|
-
updateAuthState(data.user, storedSession);
|
|
172
|
-
} else if (response.status === 401) {
|
|
173
|
-
try {
|
|
174
|
-
const refreshResponse = await authFetch(buildUrl("refresh"), {
|
|
175
|
-
method: "POST",
|
|
176
|
-
headers: { "Content-Type": "application/json" },
|
|
177
|
-
body: JSON.stringify({ refreshToken: storedSession.refresh_token })
|
|
178
|
-
});
|
|
179
|
-
if (refreshResponse.ok) {
|
|
180
|
-
const refreshData = await refreshResponse.json();
|
|
181
|
-
const newSession = {
|
|
182
|
-
...storedSession,
|
|
183
|
-
access_token: refreshData.access_token,
|
|
184
|
-
expires_at: refreshData.expires_at
|
|
185
|
-
};
|
|
186
|
-
const userResponse = await authFetch(buildUrl("me"), {
|
|
187
|
-
headers: {
|
|
188
|
-
Authorization: `Bearer ${newSession.access_token}`
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
if (userResponse.ok) {
|
|
192
|
-
const userData = await userResponse.json();
|
|
193
|
-
updateAuthState(userData.user, newSession);
|
|
194
|
-
} else {
|
|
195
|
-
updateAuthState(null, null);
|
|
196
|
-
}
|
|
197
|
-
} else {
|
|
198
|
-
updateAuthState(null, null);
|
|
199
|
-
}
|
|
200
|
-
} catch {
|
|
201
|
-
updateAuthState(null, null);
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
updateAuthState(null, null);
|
|
205
|
-
}
|
|
206
|
-
} catch (err) {
|
|
207
|
-
console.error("Failed to fetch user:", err);
|
|
208
|
-
updateAuthState(null, null);
|
|
209
|
-
} finally {
|
|
210
|
-
setLoading(false);
|
|
211
|
-
}
|
|
212
|
-
}, [projectId, loadSession, buildUrl, updateAuthState]);
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
if (projectId) {
|
|
215
|
-
fetchUser();
|
|
216
|
-
} else {
|
|
217
|
-
setLoading(false);
|
|
218
|
-
}
|
|
219
|
-
return () => {
|
|
220
|
-
if (refreshTimeoutRef.current) {
|
|
221
|
-
clearTimeout(refreshTimeoutRef.current);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}, [projectId, fetchUser]);
|
|
225
|
-
const login = useCallback(
|
|
226
|
-
async (credentials) => {
|
|
227
|
-
setError(null);
|
|
228
|
-
setLoading(true);
|
|
229
|
-
try {
|
|
230
|
-
const response = await authFetch(buildUrl("login"), {
|
|
231
|
-
method: "POST",
|
|
232
|
-
headers: { "Content-Type": "application/json" },
|
|
233
|
-
body: JSON.stringify(credentials)
|
|
234
|
-
});
|
|
235
|
-
const data = await response.json();
|
|
236
|
-
if (!response.ok) {
|
|
237
|
-
throw authErrorFromResponse(response, data, "Login failed");
|
|
238
|
-
}
|
|
239
|
-
const authResponse = data;
|
|
240
|
-
updateAuthState(authResponse.user, authResponse.session);
|
|
241
|
-
} catch (err) {
|
|
242
|
-
const message = err instanceof Error ? err.message : "Login failed";
|
|
243
|
-
setError(message);
|
|
244
|
-
throw err;
|
|
245
|
-
} finally {
|
|
246
|
-
setLoading(false);
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
[buildUrl, updateAuthState]
|
|
250
|
-
);
|
|
251
|
-
const signup = useCallback(
|
|
252
|
-
async (credentials) => {
|
|
253
|
-
setError(null);
|
|
254
|
-
setLoading(true);
|
|
255
|
-
try {
|
|
256
|
-
const response = await authFetch(buildUrl("signup"), {
|
|
257
|
-
method: "POST",
|
|
258
|
-
headers: { "Content-Type": "application/json" },
|
|
259
|
-
body: JSON.stringify(credentials)
|
|
260
|
-
});
|
|
261
|
-
const data = await response.json();
|
|
262
|
-
if (!response.ok) {
|
|
263
|
-
throw authErrorFromResponse(response, data, "Signup failed");
|
|
264
|
-
}
|
|
265
|
-
const authResponse = data;
|
|
266
|
-
if (authResponse.needsVerification) {
|
|
267
|
-
return {
|
|
268
|
-
status: "needs_verification",
|
|
269
|
-
email: credentials.email
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
if (authResponse.needsApproval) {
|
|
273
|
-
updateAuthState(authResponse.user, authResponse.session);
|
|
274
|
-
return { status: "needs_approval", user: authResponse.user };
|
|
275
|
-
}
|
|
276
|
-
if (authResponse.session.access_token) {
|
|
277
|
-
updateAuthState(authResponse.user, authResponse.session);
|
|
278
|
-
return { status: "authenticated", user: authResponse.user };
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
status: "needs_verification",
|
|
282
|
-
email: credentials.email
|
|
283
|
-
};
|
|
284
|
-
} catch (err) {
|
|
285
|
-
const message = err instanceof Error ? err.message : "Signup failed";
|
|
286
|
-
setError(message);
|
|
287
|
-
throw err;
|
|
288
|
-
} finally {
|
|
289
|
-
setLoading(false);
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
[buildUrl, updateAuthState]
|
|
293
|
-
);
|
|
294
|
-
const logout = useCallback(async () => {
|
|
295
|
-
try {
|
|
296
|
-
if (session) {
|
|
297
|
-
await authFetch(buildUrl("logout"), {
|
|
298
|
-
method: "POST",
|
|
299
|
-
headers: {
|
|
300
|
-
Authorization: `Bearer ${session.access_token}`
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
} catch (err) {
|
|
305
|
-
console.error("Logout error:", err);
|
|
306
|
-
} finally {
|
|
307
|
-
updateAuthState(null, null);
|
|
308
|
-
if (refreshTimeoutRef.current) {
|
|
309
|
-
clearTimeout(refreshTimeoutRef.current);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}, [session, buildUrl, updateAuthState]);
|
|
313
|
-
const updateProfile = useCallback(
|
|
314
|
-
async (data) => {
|
|
315
|
-
if (!session) {
|
|
316
|
-
throw new AuthError("Not authenticated", 401);
|
|
317
|
-
}
|
|
318
|
-
setError(null);
|
|
319
|
-
try {
|
|
320
|
-
const response = await authFetch(buildUrl("me"), {
|
|
321
|
-
method: "PATCH",
|
|
322
|
-
headers: {
|
|
323
|
-
"Content-Type": "application/json",
|
|
324
|
-
Authorization: `Bearer ${session.access_token}`
|
|
325
|
-
},
|
|
326
|
-
body: JSON.stringify(data)
|
|
327
|
-
});
|
|
328
|
-
const result = await response.json();
|
|
329
|
-
if (!response.ok) {
|
|
330
|
-
throw authErrorFromResponse(response, result, "Update failed");
|
|
331
|
-
}
|
|
332
|
-
setUser(result.user);
|
|
333
|
-
} catch (err) {
|
|
334
|
-
const message = err instanceof Error ? err.message : "Update failed";
|
|
335
|
-
setError(message);
|
|
336
|
-
throw err;
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
[session, buildUrl]
|
|
340
|
-
);
|
|
341
|
-
const refreshSession = useCallback(async () => {
|
|
342
|
-
if (!session)
|
|
343
|
-
return;
|
|
344
|
-
const response = await authFetch(buildUrl("refresh"), {
|
|
345
|
-
method: "POST",
|
|
346
|
-
headers: { "Content-Type": "application/json" },
|
|
347
|
-
body: JSON.stringify({ refreshToken: session.refresh_token })
|
|
348
|
-
});
|
|
349
|
-
const data = await response.json();
|
|
350
|
-
if (!response.ok) {
|
|
351
|
-
throw authErrorFromResponse(response, data, "Refresh failed");
|
|
352
|
-
}
|
|
353
|
-
const refreshData = data;
|
|
354
|
-
const newSession = {
|
|
355
|
-
...session,
|
|
356
|
-
access_token: refreshData.access_token,
|
|
357
|
-
expires_at: refreshData.expires_at
|
|
358
|
-
};
|
|
359
|
-
updateAuthState(user, newSession);
|
|
360
|
-
}, [session, user, buildUrl, updateAuthState]);
|
|
361
|
-
const forgotPassword = useCallback(
|
|
362
|
-
async (email) => {
|
|
363
|
-
setError(null);
|
|
364
|
-
try {
|
|
365
|
-
const response = await authFetch(buildUrl("forgot-password"), {
|
|
366
|
-
method: "POST",
|
|
367
|
-
headers: { "Content-Type": "application/json" },
|
|
368
|
-
body: JSON.stringify({ email })
|
|
369
|
-
});
|
|
370
|
-
const data = await response.json();
|
|
371
|
-
if (!response.ok) {
|
|
372
|
-
throw authErrorFromResponse(response, data, "Request failed");
|
|
373
|
-
}
|
|
374
|
-
} catch (err) {
|
|
375
|
-
const message = err instanceof Error ? err.message : "Request failed";
|
|
376
|
-
setError(message);
|
|
377
|
-
throw err;
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
[buildUrl]
|
|
381
|
-
);
|
|
382
|
-
const resetPassword = useCallback(
|
|
383
|
-
async (token, newPassword) => {
|
|
384
|
-
setError(null);
|
|
385
|
-
try {
|
|
386
|
-
const response = await authFetch(buildUrl("reset-password"), {
|
|
387
|
-
method: "POST",
|
|
388
|
-
headers: { "Content-Type": "application/json" },
|
|
389
|
-
body: JSON.stringify({ token, password: newPassword })
|
|
390
|
-
});
|
|
391
|
-
const data = await response.json();
|
|
392
|
-
if (!response.ok) {
|
|
393
|
-
throw authErrorFromResponse(response, data, "Reset failed");
|
|
394
|
-
}
|
|
395
|
-
} catch (err) {
|
|
396
|
-
const message = err instanceof Error ? err.message : "Reset failed";
|
|
397
|
-
setError(message);
|
|
398
|
-
throw err;
|
|
399
|
-
}
|
|
400
|
-
},
|
|
401
|
-
[buildUrl]
|
|
402
|
-
);
|
|
403
|
-
const signInWithOAuth = useCallback(
|
|
404
|
-
(provider) => {
|
|
405
|
-
if (!projectId) {
|
|
406
|
-
setError("Project ID is required");
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
const currentUrl = window.location.origin + window.location.pathname;
|
|
410
|
-
const oauthUrl = `${baseUrl}/${projectId}/auth/oauth/${provider}?redirect_uri=${encodeURIComponent(currentUrl)}`;
|
|
411
|
-
window.location.href = oauthUrl;
|
|
412
|
-
},
|
|
413
|
-
[projectId, baseUrl]
|
|
414
|
-
);
|
|
415
|
-
const verifyOTP = useCallback(
|
|
416
|
-
async (email, code) => {
|
|
417
|
-
setError(null);
|
|
418
|
-
setLoading(true);
|
|
419
|
-
try {
|
|
420
|
-
const response = await authFetch(buildUrl("verify-email"), {
|
|
421
|
-
method: "POST",
|
|
422
|
-
headers: { "Content-Type": "application/json" },
|
|
423
|
-
body: JSON.stringify({ email, otp: code })
|
|
424
|
-
});
|
|
425
|
-
const data = await response.json();
|
|
426
|
-
if (!response.ok) {
|
|
427
|
-
throw authErrorFromResponse(response, data, "Verification failed");
|
|
428
|
-
}
|
|
429
|
-
if (data.session) {
|
|
430
|
-
updateAuthState(data.user, data.session);
|
|
431
|
-
}
|
|
432
|
-
} catch (err) {
|
|
433
|
-
const message = err instanceof Error ? err.message : "Verification failed";
|
|
434
|
-
setError(message);
|
|
435
|
-
throw err;
|
|
436
|
-
} finally {
|
|
437
|
-
setLoading(false);
|
|
438
|
-
}
|
|
439
|
-
},
|
|
440
|
-
[buildUrl, updateAuthState]
|
|
441
|
-
);
|
|
442
|
-
const resendOTP = useCallback(
|
|
443
|
-
async (email) => {
|
|
444
|
-
setError(null);
|
|
445
|
-
try {
|
|
446
|
-
const response = await authFetch(buildUrl("resend-verification"), {
|
|
447
|
-
method: "POST",
|
|
448
|
-
headers: { "Content-Type": "application/json" },
|
|
449
|
-
body: JSON.stringify({ email })
|
|
450
|
-
});
|
|
451
|
-
const data = await response.json();
|
|
452
|
-
if (!response.ok) {
|
|
453
|
-
throw authErrorFromResponse(response, data, "Failed to resend code");
|
|
454
|
-
}
|
|
455
|
-
} catch (err) {
|
|
456
|
-
const message = err instanceof Error ? err.message : "Failed to resend code";
|
|
457
|
-
setError(message);
|
|
458
|
-
throw err;
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
[buildUrl]
|
|
462
|
-
);
|
|
463
|
-
const fetchAuthConfig = useCallback(async () => {
|
|
464
|
-
if (!projectId)
|
|
465
|
-
return;
|
|
466
|
-
try {
|
|
467
|
-
const response = await fetch(
|
|
468
|
-
`${baseUrl}/${projectId}/auth/config`,
|
|
469
|
-
withSdkHeader()
|
|
470
|
-
);
|
|
471
|
-
noteDeprecationWarning(response);
|
|
472
|
-
if (response.ok) {
|
|
473
|
-
const data = await response.json();
|
|
474
|
-
setAuthConfig(data.config || null);
|
|
475
|
-
setVisibilityConfig(
|
|
476
|
-
data.visibility || {
|
|
477
|
-
projectName: "App",
|
|
478
|
-
visibility: "public",
|
|
479
|
-
requireLogin: false,
|
|
480
|
-
logoUrl: null,
|
|
481
|
-
welcomeMessage: null
|
|
482
|
-
}
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
} catch (err) {
|
|
486
|
-
console.error("Failed to fetch auth config:", err);
|
|
487
|
-
}
|
|
488
|
-
}, [projectId, baseUrl]);
|
|
489
|
-
const parseOAuthCallback = useCallback(() => {
|
|
490
|
-
if (typeof window === "undefined")
|
|
491
|
-
return;
|
|
492
|
-
const hash = window.location.hash;
|
|
493
|
-
if (hash && hash.startsWith("#auth=")) {
|
|
494
|
-
try {
|
|
495
|
-
const authData = decodeURIComponent(hash.substring(6));
|
|
496
|
-
const tokenData = JSON.parse(authData);
|
|
497
|
-
if (tokenData.access_token && tokenData.refresh_token) {
|
|
498
|
-
const newSession = {
|
|
499
|
-
access_token: tokenData.access_token,
|
|
500
|
-
refresh_token: tokenData.refresh_token,
|
|
501
|
-
expires_at: tokenData.expires_at
|
|
502
|
-
};
|
|
503
|
-
saveSession(newSession);
|
|
504
|
-
setSession(newSession);
|
|
505
|
-
window.history.replaceState({}, "", window.location.pathname);
|
|
506
|
-
return true;
|
|
507
|
-
}
|
|
508
|
-
} catch {
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const params = new URLSearchParams(window.location.search);
|
|
512
|
-
const verifyEmailToken = params.get("verify_email");
|
|
513
|
-
if (verifyEmailToken && projectId) {
|
|
514
|
-
fetch(
|
|
515
|
-
buildUrl("verify-email"),
|
|
516
|
-
withSdkHeader({
|
|
517
|
-
method: "POST",
|
|
518
|
-
headers: { "Content-Type": "application/json" },
|
|
519
|
-
body: JSON.stringify({ token: verifyEmailToken })
|
|
520
|
-
})
|
|
521
|
-
).then((res) => res.json()).then(() => {
|
|
522
|
-
window.history.replaceState({}, "", window.location.pathname);
|
|
523
|
-
}).catch(() => {
|
|
524
|
-
window.history.replaceState({}, "", window.location.pathname);
|
|
525
|
-
});
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
const accessToken = params.get("access_token");
|
|
529
|
-
const refreshToken = params.get("refresh_token");
|
|
530
|
-
const expiresAt = params.get("expires_at");
|
|
531
|
-
if (accessToken && refreshToken && expiresAt) {
|
|
532
|
-
const newSession = {
|
|
533
|
-
access_token: accessToken,
|
|
534
|
-
refresh_token: refreshToken,
|
|
535
|
-
expires_at: expiresAt
|
|
536
|
-
};
|
|
537
|
-
saveSession(newSession);
|
|
538
|
-
setSession(newSession);
|
|
539
|
-
window.history.replaceState({}, "", window.location.pathname);
|
|
540
|
-
return true;
|
|
541
|
-
}
|
|
542
|
-
return false;
|
|
543
|
-
}, [projectId, buildUrl, saveSession]);
|
|
544
|
-
useEffect(() => {
|
|
545
|
-
fetchAuthConfig();
|
|
546
|
-
}, [fetchAuthConfig]);
|
|
547
|
-
useEffect(() => {
|
|
548
|
-
parseOAuthCallback();
|
|
549
|
-
}, [parseOAuthCallback]);
|
|
550
|
-
const value = {
|
|
551
|
-
user,
|
|
552
|
-
session,
|
|
553
|
-
loading,
|
|
554
|
-
error,
|
|
555
|
-
login,
|
|
556
|
-
signup,
|
|
557
|
-
logout,
|
|
558
|
-
signInWithOAuth,
|
|
559
|
-
verifyOTP,
|
|
560
|
-
resendOTP,
|
|
561
|
-
updateProfile,
|
|
562
|
-
refreshSession,
|
|
563
|
-
forgotPassword,
|
|
564
|
-
resetPassword,
|
|
565
|
-
setProjectId,
|
|
566
|
-
projectId,
|
|
567
|
-
authConfig,
|
|
568
|
-
visibilityConfig
|
|
569
|
-
};
|
|
570
|
-
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
|
|
571
|
-
}
|
|
572
|
-
function useAuthContext() {
|
|
573
|
-
const context = useContext(AuthContext);
|
|
574
|
-
if (!context) {
|
|
575
|
-
throw new Error("useAuthContext must be used within an AuthProvider");
|
|
576
|
-
}
|
|
577
|
-
return context;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// src/use-auth.ts
|
|
581
|
-
function useAuth() {
|
|
582
|
-
return useAuthContext();
|
|
583
|
-
}
|
|
584
|
-
function useUser() {
|
|
585
|
-
const { user, loading } = useAuthContext();
|
|
586
|
-
return { user, loading };
|
|
587
|
-
}
|
|
588
|
-
function useSession() {
|
|
589
|
-
const { session, loading } = useAuthContext();
|
|
590
|
-
return { session, loading };
|
|
591
|
-
}
|
|
592
|
-
function useAuthRequired() {
|
|
593
|
-
const { user, loading, session } = useAuthContext();
|
|
594
|
-
if (loading) {
|
|
595
|
-
return { user: null, session: null, loading: true };
|
|
596
|
-
}
|
|
597
|
-
if (!user) {
|
|
598
|
-
throw new Error("Authentication required");
|
|
599
|
-
}
|
|
600
|
-
return { user, session, loading: false };
|
|
601
|
-
}
|
|
602
|
-
function useIsOwner() {
|
|
603
|
-
const { user, session, loading } = useAuthContext();
|
|
604
|
-
if (loading || !user || !session)
|
|
605
|
-
return false;
|
|
606
|
-
if (user.is_owner === true)
|
|
607
|
-
return true;
|
|
608
|
-
const claim = decodeIsOwnerClaim(session.access_token);
|
|
609
|
-
return claim === true;
|
|
610
|
-
}
|
|
611
|
-
function useIsWorkspaceMember() {
|
|
612
|
-
const [isMember, setIsMember] = useState2(() => isDevHost());
|
|
613
|
-
useEffect2(() => {
|
|
614
|
-
if (typeof window === "undefined")
|
|
615
|
-
return;
|
|
616
|
-
let cancelled = false;
|
|
617
|
-
(async () => {
|
|
618
|
-
try {
|
|
619
|
-
const res = await fetch("/__instroc/workspace-status", {
|
|
620
|
-
credentials: "include",
|
|
621
|
-
cache: "no-store"
|
|
622
|
-
});
|
|
623
|
-
if (cancelled)
|
|
624
|
-
return;
|
|
625
|
-
if (!res.ok) {
|
|
626
|
-
setIsMember(isDevHost());
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
const data = await res.json();
|
|
630
|
-
setIsMember(data.isWorkspaceMember === true);
|
|
631
|
-
} catch {
|
|
632
|
-
if (!cancelled)
|
|
633
|
-
setIsMember(isDevHost());
|
|
634
|
-
}
|
|
635
|
-
})();
|
|
636
|
-
return () => {
|
|
637
|
-
cancelled = true;
|
|
638
|
-
};
|
|
639
|
-
}, []);
|
|
640
|
-
return isMember;
|
|
641
|
-
}
|
|
642
|
-
function isDevHost() {
|
|
643
|
-
if (typeof window === "undefined")
|
|
644
|
-
return false;
|
|
645
|
-
const h = window.location.hostname;
|
|
646
|
-
return h === "localhost" || h === "127.0.0.1" || h.endsWith(".fly.dev") || h.endsWith(".workers.dev") || h === "preview.instroc.app";
|
|
647
|
-
}
|
|
648
|
-
function decodeIsOwnerClaim(accessToken) {
|
|
649
|
-
try {
|
|
650
|
-
const parts = accessToken.split(".");
|
|
651
|
-
if (parts.length !== 3)
|
|
652
|
-
return void 0;
|
|
653
|
-
const payload = parts[1];
|
|
654
|
-
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
655
|
-
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
656
|
-
const json = typeof atob !== "undefined" ? atob(padded) : Buffer.from(padded, "base64").toString("utf-8");
|
|
657
|
-
const decoded = JSON.parse(json);
|
|
658
|
-
return decoded.is_owner;
|
|
659
|
-
} catch {
|
|
660
|
-
return void 0;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// src/forms/use-form-action.ts
|
|
665
|
-
function resolveErrorMessage(err, messages, fallback) {
|
|
666
|
-
if (err instanceof AuthError) {
|
|
667
|
-
return messages?.[err.status] ?? err.message ?? fallback;
|
|
668
|
-
}
|
|
669
|
-
if (err instanceof Error)
|
|
670
|
-
return err.message;
|
|
671
|
-
return fallback;
|
|
672
|
-
}
|
|
673
|
-
function applyErrorResult(err, onError, messages, fallback, setError) {
|
|
674
|
-
const override = onError?.(err);
|
|
675
|
-
if (override === null) {
|
|
676
|
-
setError(null);
|
|
677
|
-
return;
|
|
678
|
-
}
|
|
679
|
-
if (typeof override === "string") {
|
|
680
|
-
setError(override);
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
setError(resolveErrorMessage(err, messages, fallback));
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// src/forms/use-login-form.ts
|
|
687
|
-
function useLoginForm(options = {}) {
|
|
688
|
-
const { login, user } = useAuth();
|
|
689
|
-
const { onSuccess, onNeedsVerification, onError, messages } = options;
|
|
690
|
-
const [loading, setLoading] = useState3(false);
|
|
691
|
-
const [error, setError] = useState3(null);
|
|
692
|
-
const mountedRef = useRef2(true);
|
|
693
|
-
useEffect3(() => {
|
|
694
|
-
mountedRef.current = true;
|
|
695
|
-
return () => {
|
|
696
|
-
mountedRef.current = false;
|
|
697
|
-
};
|
|
698
|
-
}, []);
|
|
699
|
-
const safeSetError = useCallback2((msg) => {
|
|
700
|
-
if (mountedRef.current)
|
|
701
|
-
setError(msg);
|
|
702
|
-
}, []);
|
|
703
|
-
const clearError = useCallback2(() => safeSetError(null), [safeSetError]);
|
|
704
|
-
const submit = useCallback2(
|
|
705
|
-
async (credentials) => {
|
|
706
|
-
if (mountedRef.current) {
|
|
707
|
-
setLoading(true);
|
|
708
|
-
setError(null);
|
|
709
|
-
}
|
|
710
|
-
try {
|
|
711
|
-
await login(credentials);
|
|
712
|
-
onSuccess?.(user ?? { id: "", email: credentials.email });
|
|
713
|
-
} catch (err) {
|
|
714
|
-
if (err instanceof AuthError && err.status === 403 && onNeedsVerification) {
|
|
715
|
-
safeSetError(null);
|
|
716
|
-
onNeedsVerification(credentials.email);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
applyErrorResult(
|
|
720
|
-
err,
|
|
721
|
-
onError,
|
|
722
|
-
messages,
|
|
723
|
-
"Login failed. Please try again.",
|
|
724
|
-
safeSetError
|
|
725
|
-
);
|
|
726
|
-
} finally {
|
|
727
|
-
if (mountedRef.current)
|
|
728
|
-
setLoading(false);
|
|
729
|
-
}
|
|
730
|
-
},
|
|
731
|
-
[
|
|
732
|
-
login,
|
|
733
|
-
user,
|
|
734
|
-
onSuccess,
|
|
735
|
-
onNeedsVerification,
|
|
736
|
-
onError,
|
|
737
|
-
messages,
|
|
738
|
-
safeSetError
|
|
739
|
-
]
|
|
740
|
-
);
|
|
741
|
-
return { submit, loading, error, setError: safeSetError, clearError };
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
// src/forms/use-signup-form.ts
|
|
745
|
-
import { useState as useState4, useCallback as useCallback3, useRef as useRef3, useEffect as useEffect4 } from "react";
|
|
746
|
-
function useSignupForm(options = {}) {
|
|
747
|
-
const { signup } = useAuth();
|
|
748
|
-
const { onSuccess, onNeedsVerification, onNeedsApproval, onError, messages } = options;
|
|
749
|
-
const [loading, setLoading] = useState4(false);
|
|
750
|
-
const [error, setError] = useState4(null);
|
|
751
|
-
const mountedRef = useRef3(true);
|
|
752
|
-
useEffect4(() => {
|
|
753
|
-
mountedRef.current = true;
|
|
754
|
-
return () => {
|
|
755
|
-
mountedRef.current = false;
|
|
756
|
-
};
|
|
757
|
-
}, []);
|
|
758
|
-
const safeSetError = useCallback3((msg) => {
|
|
759
|
-
if (mountedRef.current)
|
|
760
|
-
setError(msg);
|
|
761
|
-
}, []);
|
|
762
|
-
const clearError = useCallback3(() => safeSetError(null), [safeSetError]);
|
|
763
|
-
const submit = useCallback3(
|
|
764
|
-
async (credentials) => {
|
|
765
|
-
if (mountedRef.current) {
|
|
766
|
-
setLoading(true);
|
|
767
|
-
setError(null);
|
|
768
|
-
}
|
|
769
|
-
try {
|
|
770
|
-
const result = await signup(credentials);
|
|
771
|
-
switch (result.status) {
|
|
772
|
-
case "authenticated":
|
|
773
|
-
onSuccess?.(result.user);
|
|
774
|
-
return;
|
|
775
|
-
case "needs_verification":
|
|
776
|
-
onNeedsVerification?.(result.email);
|
|
777
|
-
return;
|
|
778
|
-
case "needs_approval":
|
|
779
|
-
onNeedsApproval?.(result.user);
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
} catch (err) {
|
|
783
|
-
applyErrorResult(
|
|
784
|
-
err,
|
|
785
|
-
onError,
|
|
786
|
-
messages,
|
|
787
|
-
"Signup failed. Please try again.",
|
|
788
|
-
safeSetError
|
|
789
|
-
);
|
|
790
|
-
} finally {
|
|
791
|
-
if (mountedRef.current)
|
|
792
|
-
setLoading(false);
|
|
793
|
-
}
|
|
794
|
-
},
|
|
795
|
-
[
|
|
796
|
-
signup,
|
|
797
|
-
onSuccess,
|
|
798
|
-
onNeedsVerification,
|
|
799
|
-
onNeedsApproval,
|
|
800
|
-
onError,
|
|
801
|
-
messages,
|
|
802
|
-
safeSetError
|
|
803
|
-
]
|
|
804
|
-
);
|
|
805
|
-
return { submit, loading, error, setError: safeSetError, clearError };
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// src/forms/use-otp-form.ts
|
|
809
|
-
import { useState as useState5, useCallback as useCallback4, useRef as useRef4, useEffect as useEffect5 } from "react";
|
|
810
|
-
function useOtpForm(options) {
|
|
811
|
-
const { verifyOTP, resendOTP } = useAuth();
|
|
812
|
-
const {
|
|
813
|
-
email,
|
|
814
|
-
onSuccess,
|
|
815
|
-
onResendSuccess,
|
|
816
|
-
onError,
|
|
817
|
-
messages,
|
|
818
|
-
resendCooldownSeconds = 60
|
|
819
|
-
} = options;
|
|
820
|
-
const [loading, setLoading] = useState5(false);
|
|
821
|
-
const [resending, setResending] = useState5(false);
|
|
822
|
-
const [resendCooldown, setResendCooldown] = useState5(0);
|
|
823
|
-
const [error, setError] = useState5(null);
|
|
824
|
-
const mountedRef = useRef4(true);
|
|
825
|
-
useEffect5(() => {
|
|
826
|
-
mountedRef.current = true;
|
|
827
|
-
return () => {
|
|
828
|
-
mountedRef.current = false;
|
|
829
|
-
};
|
|
830
|
-
}, []);
|
|
831
|
-
useEffect5(() => {
|
|
832
|
-
if (resendCooldown <= 0)
|
|
833
|
-
return;
|
|
834
|
-
const id = setTimeout(() => setResendCooldown((s) => s - 1), 1e3);
|
|
835
|
-
return () => clearTimeout(id);
|
|
836
|
-
}, [resendCooldown]);
|
|
837
|
-
const safeSetError = useCallback4((msg) => {
|
|
838
|
-
if (mountedRef.current)
|
|
839
|
-
setError(msg);
|
|
840
|
-
}, []);
|
|
841
|
-
const clearError = useCallback4(() => safeSetError(null), [safeSetError]);
|
|
842
|
-
const submit = useCallback4(
|
|
843
|
-
async (code) => {
|
|
844
|
-
if (mountedRef.current) {
|
|
845
|
-
setLoading(true);
|
|
846
|
-
setError(null);
|
|
847
|
-
}
|
|
848
|
-
try {
|
|
849
|
-
await verifyOTP(email, code);
|
|
850
|
-
onSuccess?.();
|
|
851
|
-
} catch (err) {
|
|
852
|
-
applyErrorResult(
|
|
853
|
-
err,
|
|
854
|
-
onError,
|
|
855
|
-
messages,
|
|
856
|
-
"Verification failed. Please try again.",
|
|
857
|
-
safeSetError
|
|
858
|
-
);
|
|
859
|
-
} finally {
|
|
860
|
-
if (mountedRef.current)
|
|
861
|
-
setLoading(false);
|
|
862
|
-
}
|
|
863
|
-
},
|
|
864
|
-
[verifyOTP, email, onSuccess, onError, messages, safeSetError]
|
|
865
|
-
);
|
|
866
|
-
const resend = useCallback4(async () => {
|
|
867
|
-
if (resendCooldown > 0)
|
|
868
|
-
return;
|
|
869
|
-
if (mountedRef.current) {
|
|
870
|
-
setResending(true);
|
|
871
|
-
setError(null);
|
|
872
|
-
}
|
|
873
|
-
try {
|
|
874
|
-
await resendOTP(email);
|
|
875
|
-
if (mountedRef.current)
|
|
876
|
-
setResendCooldown(resendCooldownSeconds);
|
|
877
|
-
onResendSuccess?.();
|
|
878
|
-
} catch (err) {
|
|
879
|
-
applyErrorResult(
|
|
880
|
-
err,
|
|
881
|
-
onError,
|
|
882
|
-
messages,
|
|
883
|
-
"Could not resend code. Please try again.",
|
|
884
|
-
safeSetError
|
|
885
|
-
);
|
|
886
|
-
} finally {
|
|
887
|
-
if (mountedRef.current)
|
|
888
|
-
setResending(false);
|
|
889
|
-
}
|
|
890
|
-
}, [
|
|
891
|
-
resendCooldown,
|
|
892
|
-
resendOTP,
|
|
893
|
-
email,
|
|
894
|
-
resendCooldownSeconds,
|
|
895
|
-
onResendSuccess,
|
|
896
|
-
onError,
|
|
897
|
-
messages,
|
|
898
|
-
safeSetError
|
|
899
|
-
]);
|
|
900
|
-
return {
|
|
901
|
-
submit,
|
|
902
|
-
resend,
|
|
903
|
-
loading,
|
|
904
|
-
resending,
|
|
905
|
-
resendCooldown,
|
|
906
|
-
error,
|
|
907
|
-
setError: safeSetError,
|
|
908
|
-
clearError
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
// src/forms/use-forgot-password-form.ts
|
|
913
|
-
import { useState as useState6, useCallback as useCallback5, useRef as useRef5, useEffect as useEffect6 } from "react";
|
|
914
|
-
function useForgotPasswordForm(options = {}) {
|
|
915
|
-
const { forgotPassword } = useAuth();
|
|
916
|
-
const { onSuccess, onError, messages } = options;
|
|
917
|
-
const [loading, setLoading] = useState6(false);
|
|
918
|
-
const [submitted, setSubmitted] = useState6(false);
|
|
919
|
-
const [error, setError] = useState6(null);
|
|
920
|
-
const mountedRef = useRef5(true);
|
|
921
|
-
useEffect6(() => {
|
|
922
|
-
mountedRef.current = true;
|
|
923
|
-
return () => {
|
|
924
|
-
mountedRef.current = false;
|
|
925
|
-
};
|
|
926
|
-
}, []);
|
|
927
|
-
const safeSetError = useCallback5((msg) => {
|
|
928
|
-
if (mountedRef.current)
|
|
929
|
-
setError(msg);
|
|
930
|
-
}, []);
|
|
931
|
-
const clearError = useCallback5(() => safeSetError(null), [safeSetError]);
|
|
932
|
-
const reset = useCallback5(() => {
|
|
933
|
-
if (mountedRef.current) {
|
|
934
|
-
setSubmitted(false);
|
|
935
|
-
setError(null);
|
|
936
|
-
}
|
|
937
|
-
}, []);
|
|
938
|
-
const submit = useCallback5(
|
|
939
|
-
async (email) => {
|
|
940
|
-
if (mountedRef.current) {
|
|
941
|
-
setLoading(true);
|
|
942
|
-
setError(null);
|
|
943
|
-
}
|
|
944
|
-
try {
|
|
945
|
-
await forgotPassword(email);
|
|
946
|
-
if (mountedRef.current)
|
|
947
|
-
setSubmitted(true);
|
|
948
|
-
onSuccess?.(email);
|
|
949
|
-
} catch (err) {
|
|
950
|
-
applyErrorResult(
|
|
951
|
-
err,
|
|
952
|
-
onError,
|
|
953
|
-
messages,
|
|
954
|
-
"Could not send reset link. Please try again.",
|
|
955
|
-
safeSetError
|
|
956
|
-
);
|
|
957
|
-
} finally {
|
|
958
|
-
if (mountedRef.current)
|
|
959
|
-
setLoading(false);
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
[forgotPassword, onSuccess, onError, messages, safeSetError]
|
|
963
|
-
);
|
|
964
|
-
return {
|
|
965
|
-
submit,
|
|
966
|
-
loading,
|
|
967
|
-
submitted,
|
|
968
|
-
error,
|
|
969
|
-
setError: safeSetError,
|
|
970
|
-
clearError,
|
|
971
|
-
reset
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// src/forms/use-reset-password-form.ts
|
|
976
|
-
import { useState as useState7, useCallback as useCallback6, useRef as useRef6, useEffect as useEffect7 } from "react";
|
|
977
|
-
function useResetPasswordForm(options) {
|
|
978
|
-
const { resetPassword } = useAuth();
|
|
979
|
-
const { token, onSuccess, onError, messages } = options;
|
|
980
|
-
const [loading, setLoading] = useState7(false);
|
|
981
|
-
const [error, setError] = useState7(null);
|
|
982
|
-
const mountedRef = useRef6(true);
|
|
983
|
-
useEffect7(() => {
|
|
984
|
-
mountedRef.current = true;
|
|
985
|
-
return () => {
|
|
986
|
-
mountedRef.current = false;
|
|
987
|
-
};
|
|
988
|
-
}, []);
|
|
989
|
-
const safeSetError = useCallback6((msg) => {
|
|
990
|
-
if (mountedRef.current)
|
|
991
|
-
setError(msg);
|
|
992
|
-
}, []);
|
|
993
|
-
const clearError = useCallback6(() => safeSetError(null), [safeSetError]);
|
|
994
|
-
const submit = useCallback6(
|
|
995
|
-
async (newPassword) => {
|
|
996
|
-
if (mountedRef.current) {
|
|
997
|
-
setLoading(true);
|
|
998
|
-
setError(null);
|
|
999
|
-
}
|
|
1000
|
-
try {
|
|
1001
|
-
await resetPassword(token, newPassword);
|
|
1002
|
-
onSuccess?.();
|
|
1003
|
-
} catch (err) {
|
|
1004
|
-
applyErrorResult(
|
|
1005
|
-
err,
|
|
1006
|
-
onError,
|
|
1007
|
-
messages,
|
|
1008
|
-
"Could not reset password. Please try again.",
|
|
1009
|
-
safeSetError
|
|
1010
|
-
);
|
|
1011
|
-
} finally {
|
|
1012
|
-
if (mountedRef.current)
|
|
1013
|
-
setLoading(false);
|
|
1014
|
-
}
|
|
1015
|
-
},
|
|
1016
|
-
[resetPassword, token, onSuccess, onError, messages, safeSetError]
|
|
1017
|
-
);
|
|
1018
|
-
return { submit, loading, error, setError: safeSetError, clearError };
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
export {
|
|
1022
|
-
AuthError,
|
|
1023
|
-
AuthProvider,
|
|
1024
|
-
useAuthContext,
|
|
1025
|
-
useAuth,
|
|
1026
|
-
useUser,
|
|
1027
|
-
useSession,
|
|
1028
|
-
useAuthRequired,
|
|
1029
|
-
useIsOwner,
|
|
1030
|
-
useIsWorkspaceMember,
|
|
1031
|
-
useLoginForm,
|
|
1032
|
-
useSignupForm,
|
|
1033
|
-
useOtpForm,
|
|
1034
|
-
useForgotPasswordForm,
|
|
1035
|
-
useResetPasswordForm
|
|
1036
|
-
};
|