@constructive-io/sheets 0.3.0
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/LICENSE +21 -0
- package/README.md +188 -0
- package/dist/advanced.cjs +5477 -0
- package/dist/advanced.cjs.map +1 -0
- package/dist/advanced.d.cts +83 -0
- package/dist/advanced.d.ts +83 -0
- package/dist/advanced.js +34 -0
- package/dist/advanced.js.map +1 -0
- package/dist/auth.cjs +1396 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +60 -0
- package/dist/auth.d.ts +60 -0
- package/dist/auth.js +19 -0
- package/dist/auth.js.map +1 -0
- package/dist/chunk-4PGPVMZB.js +670 -0
- package/dist/chunk-4PGPVMZB.js.map +1 -0
- package/dist/chunk-FNVHSOQQ.js +1314 -0
- package/dist/chunk-FNVHSOQQ.js.map +1 -0
- package/dist/chunk-GGECS2BP.js +17 -0
- package/dist/chunk-GGECS2BP.js.map +1 -0
- package/dist/chunk-GLVZSPV2.js +43 -0
- package/dist/chunk-GLVZSPV2.js.map +1 -0
- package/dist/chunk-H4JJTMP5.js +160 -0
- package/dist/chunk-H4JJTMP5.js.map +1 -0
- package/dist/chunk-ODUBS2NL.js +100 -0
- package/dist/chunk-ODUBS2NL.js.map +1 -0
- package/dist/chunk-PZL2BCWF.js +168 -0
- package/dist/chunk-PZL2BCWF.js.map +1 -0
- package/dist/chunk-TU7ATZ4X.js +4494 -0
- package/dist/chunk-TU7ATZ4X.js.map +1 -0
- package/dist/chunk-X7DHTSOX.js +21 -0
- package/dist/chunk-X7DHTSOX.js.map +1 -0
- package/dist/chunk-YDQQA46V.js +13 -0
- package/dist/chunk-YDQQA46V.js.map +1 -0
- package/dist/date-editor-CXKKGNL6.js +361 -0
- package/dist/date-editor-CXKKGNL6.js.map +1 -0
- package/dist/editor-props-M6Dh0P9f.d.cts +245 -0
- package/dist/editor-props-M6Dh0P9f.d.ts +245 -0
- package/dist/index.cjs +15861 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1650 -0
- package/dist/index.d.ts +1650 -0
- package/dist/index.js +8470 -0
- package/dist/index.js.map +1 -0
- package/dist/map-picker-VTKDS6CM.js +290 -0
- package/dist/map-picker-VTKDS6CM.js.map +1 -0
- package/dist/sheets-context-CojEFlaY.d.cts +214 -0
- package/dist/sheets-context-Da55TTR9.d.ts +214 -0
- package/dist/testing.cjs +1113 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +45 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +269 -0
- package/dist/testing.js.map +1 -0
- package/package.json +144 -0
package/dist/auth.cjs
ADDED
|
@@ -0,0 +1,1396 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/auth/index.ts
|
|
32
|
+
var auth_exports = {};
|
|
33
|
+
__export(auth_exports, {
|
|
34
|
+
SheetsAuthGate: () => SheetsAuthGate,
|
|
35
|
+
useSheetsForgotPassword: () => useSheetsForgotPassword,
|
|
36
|
+
useSheetsLogin: () => useSheetsLogin,
|
|
37
|
+
useSheetsRegister: () => useSheetsRegister,
|
|
38
|
+
useSheetsResetPassword: () => useSheetsResetPassword
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(auth_exports);
|
|
41
|
+
|
|
42
|
+
// src/auth/auth-gate.tsx
|
|
43
|
+
var import_react6 = require("react");
|
|
44
|
+
|
|
45
|
+
// src/context/sheets-context.ts
|
|
46
|
+
var import_react = require("react");
|
|
47
|
+
var SheetsContext = (0, import_react.createContext)(null);
|
|
48
|
+
function useSheetsContext() {
|
|
49
|
+
const ctx = (0, import_react.useContext)(SheetsContext);
|
|
50
|
+
if (!ctx) {
|
|
51
|
+
throw new Error("useSheetsContext must be used within a <SheetsProvider>");
|
|
52
|
+
}
|
|
53
|
+
return ctx;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/store/sheets-store.ts
|
|
57
|
+
var import_react2 = require("react");
|
|
58
|
+
var import_zustand = require("zustand");
|
|
59
|
+
var SheetsStoreContext = (0, import_react2.createContext)(null);
|
|
60
|
+
function useSheetsStore(selector) {
|
|
61
|
+
const store = (0, import_react2.useContext)(SheetsStoreContext);
|
|
62
|
+
if (!store) {
|
|
63
|
+
throw new Error("useSheetsStore must be used within a <SheetsProvider>");
|
|
64
|
+
}
|
|
65
|
+
return (0, import_zustand.useStore)(store, selector);
|
|
66
|
+
}
|
|
67
|
+
function useSheetsStoreApi() {
|
|
68
|
+
const store = (0, import_react2.useContext)(SheetsStoreContext);
|
|
69
|
+
if (!store) {
|
|
70
|
+
throw new Error("useSheetsStoreApi must be used within a <SheetsProvider>");
|
|
71
|
+
}
|
|
72
|
+
return store;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/auth/hooks/use-login.ts
|
|
76
|
+
var import_react_query = require("@tanstack/react-query");
|
|
77
|
+
|
|
78
|
+
// src/auth/utils/auth-errors.ts
|
|
79
|
+
var ERROR_CODES = {
|
|
80
|
+
// Auth errors - login
|
|
81
|
+
INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
|
|
82
|
+
// Generic - prevents user enumeration
|
|
83
|
+
INCORRECT_PASSWORD: "INCORRECT_PASSWORD",
|
|
84
|
+
ACCOUNT_LOCKED_EXCEED_ATTEMPTS: "ACCOUNT_LOCKED_EXCEED_ATTEMPTS",
|
|
85
|
+
ACCOUNT_DISABLED: "ACCOUNT_DISABLED",
|
|
86
|
+
// Password validation errors
|
|
87
|
+
PASSWORD_INSECURE: "PASSWORD_INSECURE",
|
|
88
|
+
PASSWORD_LEN: "PASSWORD_LEN",
|
|
89
|
+
// Registration errors
|
|
90
|
+
ACCOUNT_EXISTS: "ACCOUNT_EXISTS",
|
|
91
|
+
// Invitation errors
|
|
92
|
+
INVITE_NOT_FOUND: "INVITE_NOT_FOUND",
|
|
93
|
+
INVITE_LIMIT: "INVITE_LIMIT",
|
|
94
|
+
INVITE_EMAIL_NOT_FOUND: "INVITE_EMAIL_NOT_FOUND"
|
|
95
|
+
};
|
|
96
|
+
var ERROR_MESSAGES = {
|
|
97
|
+
[ERROR_CODES.INVALID_CREDENTIALS]: "Invalid email or password.",
|
|
98
|
+
[ERROR_CODES.INCORRECT_PASSWORD]: "The password you entered is incorrect. Please try again.",
|
|
99
|
+
[ERROR_CODES.ACCOUNT_LOCKED_EXCEED_ATTEMPTS]: "Your account has been temporarily locked due to too many failed login attempts. Please try again later or reset your password.",
|
|
100
|
+
[ERROR_CODES.ACCOUNT_DISABLED]: "Your account has been disabled. Please contact support for assistance.",
|
|
101
|
+
[ERROR_CODES.PASSWORD_INSECURE]: "This password is not secure enough. Please choose a stronger password.",
|
|
102
|
+
[ERROR_CODES.PASSWORD_LEN]: "Password must be between 8 and 63 characters long.",
|
|
103
|
+
[ERROR_CODES.ACCOUNT_EXISTS]: "An account with this email already exists. Please sign in or use a different email.",
|
|
104
|
+
[ERROR_CODES.INVITE_NOT_FOUND]: "The invitation code is invalid or has expired. Please check the code or request a new invitation.",
|
|
105
|
+
[ERROR_CODES.INVITE_LIMIT]: "This invitation has reached its usage limit. Please request a new invitation.",
|
|
106
|
+
[ERROR_CODES.INVITE_EMAIL_NOT_FOUND]: "This email is not associated with the invitation. Please use the email address the invitation was sent to."
|
|
107
|
+
};
|
|
108
|
+
var DEFAULT_ERROR_MESSAGE = "Something went wrong. Please try again.";
|
|
109
|
+
var AuthError = class _AuthError extends Error {
|
|
110
|
+
code;
|
|
111
|
+
userMessage;
|
|
112
|
+
constructor(code, customMessage) {
|
|
113
|
+
const userMessage = customMessage ?? ERROR_MESSAGES[code];
|
|
114
|
+
super(userMessage);
|
|
115
|
+
this.name = "AuthError";
|
|
116
|
+
this.code = code;
|
|
117
|
+
this.userMessage = userMessage;
|
|
118
|
+
if (Error.captureStackTrace) {
|
|
119
|
+
Error.captureStackTrace(this, _AuthError);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if an error is an AuthError with a specific code.
|
|
124
|
+
*/
|
|
125
|
+
static isCode(error, code) {
|
|
126
|
+
return error instanceof _AuthError && error.code === code;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function createInvalidCredentialsError() {
|
|
130
|
+
return new AuthError("INVALID_CREDENTIALS");
|
|
131
|
+
}
|
|
132
|
+
function isGraphQLErrorLike(value) {
|
|
133
|
+
if (!value || typeof value !== "object") return false;
|
|
134
|
+
return "message" in value || "extensions" in value;
|
|
135
|
+
}
|
|
136
|
+
function isValidationError(value) {
|
|
137
|
+
if (!value || typeof value !== "object") return false;
|
|
138
|
+
const err = value;
|
|
139
|
+
return err.name === "ZodError" && Array.isArray(err.issues) && err.issues.length > 0 && typeof err.issues[0]?.message === "string";
|
|
140
|
+
}
|
|
141
|
+
function extractErrorCode(error, knownCodes) {
|
|
142
|
+
if (error instanceof AuthError) {
|
|
143
|
+
return error.code;
|
|
144
|
+
}
|
|
145
|
+
if (error && typeof error === "object" && "errors" in error) {
|
|
146
|
+
const gqlErrors = error.errors;
|
|
147
|
+
if (Array.isArray(gqlErrors) && gqlErrors.length > 0) {
|
|
148
|
+
const firstError = gqlErrors[0];
|
|
149
|
+
if (firstError.extensions?.code) return String(firstError.extensions.code);
|
|
150
|
+
if (firstError.message) {
|
|
151
|
+
const codeMatch2 = firstError.message.match(/\(\s*[Cc]ode:\s*([A-Z_]+)\s*\)/);
|
|
152
|
+
if (codeMatch2) return codeMatch2[1];
|
|
153
|
+
for (const code of knownCodes) {
|
|
154
|
+
if (firstError.message.includes(code)) return code;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (isGraphQLErrorLike(error) && error.extensions?.code) {
|
|
160
|
+
return String(error.extensions.code);
|
|
161
|
+
}
|
|
162
|
+
if (error && typeof error === "object" && "code" in error) {
|
|
163
|
+
const code = error.code;
|
|
164
|
+
if (typeof code === "string") return code;
|
|
165
|
+
}
|
|
166
|
+
let message = null;
|
|
167
|
+
if (error instanceof Error) {
|
|
168
|
+
message = error.message;
|
|
169
|
+
} else if (isGraphQLErrorLike(error) && error.message) {
|
|
170
|
+
message = error.message;
|
|
171
|
+
} else if (typeof error === "string") {
|
|
172
|
+
message = error;
|
|
173
|
+
}
|
|
174
|
+
if (!message) return null;
|
|
175
|
+
const codeMatch = message.match(/\(\s*[Cc]ode:\s*([A-Z_]+)\s*\)/);
|
|
176
|
+
if (codeMatch) {
|
|
177
|
+
return codeMatch[1];
|
|
178
|
+
}
|
|
179
|
+
for (const code of knownCodes) {
|
|
180
|
+
if (message.includes(code)) {
|
|
181
|
+
return code;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
function isTechnicalMessage(message) {
|
|
187
|
+
const lower = message.toLowerCase();
|
|
188
|
+
return lower.includes("graphql") || lower.includes("fetch") || lower.includes("network") || lower.includes("econnrefused") || lower.includes("undefined") || lower.includes("null") || lower.includes("timeout") || lower.includes("connection") || lower.includes("socket") || lower.includes("enotfound") || lower.includes("abort");
|
|
189
|
+
}
|
|
190
|
+
function parseGraphQLError(error, options = {}) {
|
|
191
|
+
if (error instanceof AuthError) {
|
|
192
|
+
return {
|
|
193
|
+
code: error.code,
|
|
194
|
+
message: error.userMessage,
|
|
195
|
+
isKnownError: true,
|
|
196
|
+
originalError: error
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
if (isValidationError(error)) {
|
|
200
|
+
const firstIssue = error.issues[0];
|
|
201
|
+
const message2 = firstIssue?.message || "Validation failed. Please check your input.";
|
|
202
|
+
return {
|
|
203
|
+
code: "VALIDATION_ERROR",
|
|
204
|
+
message: message2,
|
|
205
|
+
isKnownError: true,
|
|
206
|
+
originalError: error
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const { defaultMessage = DEFAULT_ERROR_MESSAGE, customMessages = {} } = options;
|
|
210
|
+
const allMessages = { ...ERROR_MESSAGES, ...customMessages };
|
|
211
|
+
const allKnownCodes = Object.keys(allMessages);
|
|
212
|
+
const code = extractErrorCode(error, allKnownCodes);
|
|
213
|
+
const isKnown = code !== null && code in allMessages;
|
|
214
|
+
let message;
|
|
215
|
+
if (isKnown && code) {
|
|
216
|
+
message = allMessages[code];
|
|
217
|
+
} else {
|
|
218
|
+
if (error instanceof Error && error.message && !isTechnicalMessage(error.message)) {
|
|
219
|
+
message = error.message;
|
|
220
|
+
} else if (error instanceof Error && isTechnicalMessage(error.message) && "errors" in error && Array.isArray(error.errors)) {
|
|
221
|
+
const innerMsg = error.errors[0]?.message;
|
|
222
|
+
message = innerMsg && !isTechnicalMessage(innerMsg) ? innerMsg : defaultMessage;
|
|
223
|
+
} else {
|
|
224
|
+
message = defaultMessage;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
code: isKnown ? code : null,
|
|
229
|
+
message,
|
|
230
|
+
isKnownError: isKnown,
|
|
231
|
+
originalError: error
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/auth/utils/token-store.ts
|
|
236
|
+
var KEY_PREFIX = "sheets-auth-token";
|
|
237
|
+
function storageKey(databaseId) {
|
|
238
|
+
return `${KEY_PREFIX}:${databaseId}`;
|
|
239
|
+
}
|
|
240
|
+
function getStorage() {
|
|
241
|
+
if (typeof window === "undefined") return null;
|
|
242
|
+
try {
|
|
243
|
+
return window.localStorage;
|
|
244
|
+
} catch {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function setStoredToken(databaseId, accessToken, expiresAt) {
|
|
249
|
+
const storage = getStorage();
|
|
250
|
+
if (!storage) return;
|
|
251
|
+
try {
|
|
252
|
+
const data = { accessToken, expiresAt };
|
|
253
|
+
storage.setItem(storageKey(databaseId), JSON.stringify(data));
|
|
254
|
+
} catch {
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/auth/auth-execute.ts
|
|
259
|
+
async function executeAuthMutation(config, query, variables) {
|
|
260
|
+
const url = config.authEndpoint || config.endpoint;
|
|
261
|
+
if (!url) {
|
|
262
|
+
throw new Error("No auth endpoint configured.");
|
|
263
|
+
}
|
|
264
|
+
const headers = {
|
|
265
|
+
"Content-Type": "application/json",
|
|
266
|
+
Accept: "application/graphql-response+json"
|
|
267
|
+
};
|
|
268
|
+
let response;
|
|
269
|
+
try {
|
|
270
|
+
response = await fetch(url, {
|
|
271
|
+
method: "POST",
|
|
272
|
+
headers,
|
|
273
|
+
body: JSON.stringify({
|
|
274
|
+
query,
|
|
275
|
+
...variables !== void 0 && { variables }
|
|
276
|
+
})
|
|
277
|
+
});
|
|
278
|
+
} catch (error) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
`Network error: ${error instanceof Error ? error.message : "Failed to connect to auth endpoint"}`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
if (!response.ok) {
|
|
284
|
+
const { status, statusText } = response;
|
|
285
|
+
try {
|
|
286
|
+
const body = await response.json();
|
|
287
|
+
if (body.errors?.length) {
|
|
288
|
+
const firstError = body.errors[0];
|
|
289
|
+
const err = new Error(firstError.message || `Auth request failed: ${status}`);
|
|
290
|
+
err.code = firstError.extensions?.code;
|
|
291
|
+
err.errors = body.errors;
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
294
|
+
} catch (e) {
|
|
295
|
+
if (e instanceof Error && e.errors) throw e;
|
|
296
|
+
}
|
|
297
|
+
throw new Error(`Auth request failed: ${status} ${statusText}`);
|
|
298
|
+
}
|
|
299
|
+
const result = await response.json();
|
|
300
|
+
if (result.errors?.length) {
|
|
301
|
+
const firstError = result.errors[0];
|
|
302
|
+
const err = new Error(firstError.message || "Auth mutation failed");
|
|
303
|
+
err.code = firstError.extensions?.code;
|
|
304
|
+
err.errors = result.errors;
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
return result.data;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/auth/auth-types.ts
|
|
311
|
+
function toAuthToken(record) {
|
|
312
|
+
if (!record?.accessToken || !record?.accessTokenExpiresAt) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
accessToken: record.accessToken,
|
|
317
|
+
expiresAt: record.accessTokenExpiresAt
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/auth/hooks/use-login.ts
|
|
322
|
+
var SIGN_IN_MUTATION = (
|
|
323
|
+
/* GraphQL */
|
|
324
|
+
`
|
|
325
|
+
mutation SignIn($input: SignInInput!) {
|
|
326
|
+
signIn(input: $input) {
|
|
327
|
+
result {
|
|
328
|
+
id
|
|
329
|
+
userId
|
|
330
|
+
accessToken
|
|
331
|
+
accessTokenExpiresAt
|
|
332
|
+
isVerified
|
|
333
|
+
totpEnabled
|
|
334
|
+
}
|
|
335
|
+
clientMutationId
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
`
|
|
339
|
+
);
|
|
340
|
+
function useSheetsLogin() {
|
|
341
|
+
const queryClient = (0, import_react_query.useQueryClient)();
|
|
342
|
+
const { config } = useSheetsContext();
|
|
343
|
+
const storeApi = useSheetsStoreApi();
|
|
344
|
+
return (0, import_react_query.useMutation)({
|
|
345
|
+
mutationKey: ["sheets", "auth", "signIn"],
|
|
346
|
+
mutationFn: async (credentials) => {
|
|
347
|
+
const result = await executeAuthMutation(
|
|
348
|
+
config,
|
|
349
|
+
SIGN_IN_MUTATION,
|
|
350
|
+
{
|
|
351
|
+
input: {
|
|
352
|
+
email: credentials.email,
|
|
353
|
+
password: credentials.password,
|
|
354
|
+
rememberMe: credentials.rememberMe
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
const signInResult = result.signIn?.result;
|
|
359
|
+
if (!signInResult) {
|
|
360
|
+
throw createInvalidCredentialsError();
|
|
361
|
+
}
|
|
362
|
+
const token = toAuthToken(signInResult);
|
|
363
|
+
if (!token) {
|
|
364
|
+
throw createInvalidCredentialsError();
|
|
365
|
+
}
|
|
366
|
+
return { token, email: credentials.email };
|
|
367
|
+
},
|
|
368
|
+
onSuccess: ({ token }) => {
|
|
369
|
+
const databaseId = config.databaseId || "default";
|
|
370
|
+
setStoredToken(databaseId, token.accessToken, token.expiresAt);
|
|
371
|
+
storeApi.getState().setAuthenticated(token.accessToken, token.expiresAt);
|
|
372
|
+
queryClient.invalidateQueries({ queryKey: ["sheets"] });
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// src/auth/hooks/use-register.ts
|
|
378
|
+
var import_react_query2 = require("@tanstack/react-query");
|
|
379
|
+
var SIGN_UP_MUTATION = (
|
|
380
|
+
/* GraphQL */
|
|
381
|
+
`
|
|
382
|
+
mutation SignUp($input: SignUpInput!) {
|
|
383
|
+
signUp(input: $input) {
|
|
384
|
+
result {
|
|
385
|
+
id
|
|
386
|
+
userId
|
|
387
|
+
accessToken
|
|
388
|
+
accessTokenExpiresAt
|
|
389
|
+
isVerified
|
|
390
|
+
totpEnabled
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
`
|
|
395
|
+
);
|
|
396
|
+
function useSheetsRegister() {
|
|
397
|
+
const queryClient = (0, import_react_query2.useQueryClient)();
|
|
398
|
+
const { config } = useSheetsContext();
|
|
399
|
+
const storeApi = useSheetsStoreApi();
|
|
400
|
+
return (0, import_react_query2.useMutation)({
|
|
401
|
+
mutationKey: ["sheets", "auth", "signUp"],
|
|
402
|
+
mutationFn: async (formData) => {
|
|
403
|
+
const result = await executeAuthMutation(
|
|
404
|
+
config,
|
|
405
|
+
SIGN_UP_MUTATION,
|
|
406
|
+
{
|
|
407
|
+
input: {
|
|
408
|
+
email: formData.email,
|
|
409
|
+
password: formData.password,
|
|
410
|
+
rememberMe: formData.rememberMe ?? true
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
);
|
|
414
|
+
const signUpResult = result.signUp?.result;
|
|
415
|
+
const token = signUpResult ? toAuthToken(signUpResult) : null;
|
|
416
|
+
return { token, email: formData.email };
|
|
417
|
+
},
|
|
418
|
+
onSuccess: ({ token }) => {
|
|
419
|
+
if (token) {
|
|
420
|
+
const databaseId = config.databaseId || "default";
|
|
421
|
+
setStoredToken(databaseId, token.accessToken, token.expiresAt);
|
|
422
|
+
storeApi.getState().setAuthenticated(token.accessToken, token.expiresAt);
|
|
423
|
+
}
|
|
424
|
+
queryClient.invalidateQueries({ queryKey: ["sheets"] });
|
|
425
|
+
},
|
|
426
|
+
onError: () => {
|
|
427
|
+
storeApi.getState().setUnauthenticated();
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// src/auth/hooks/use-forgot-password.ts
|
|
433
|
+
var import_react_query3 = require("@tanstack/react-query");
|
|
434
|
+
var FORGOT_PASSWORD_MUTATION = (
|
|
435
|
+
/* GraphQL */
|
|
436
|
+
`
|
|
437
|
+
mutation ForgotPassword($input: ForgotPasswordInput!) {
|
|
438
|
+
forgotPassword(input: $input) {
|
|
439
|
+
clientMutationId
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
`
|
|
443
|
+
);
|
|
444
|
+
function useSheetsForgotPassword() {
|
|
445
|
+
const { config } = useSheetsContext();
|
|
446
|
+
return (0, import_react_query3.useMutation)({
|
|
447
|
+
mutationKey: ["sheets", "auth", "forgotPassword"],
|
|
448
|
+
mutationFn: async ({ email }) => {
|
|
449
|
+
await executeAuthMutation(
|
|
450
|
+
config,
|
|
451
|
+
FORGOT_PASSWORD_MUTATION,
|
|
452
|
+
{
|
|
453
|
+
input: { email }
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
return { email };
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/auth/hooks/use-reset-password.ts
|
|
462
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
463
|
+
var RESET_PASSWORD_MUTATION = (
|
|
464
|
+
/* GraphQL */
|
|
465
|
+
`
|
|
466
|
+
mutation ResetPassword($input: ResetPasswordInput!) {
|
|
467
|
+
resetPassword(input: $input) {
|
|
468
|
+
result
|
|
469
|
+
clientMutationId
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
`
|
|
473
|
+
);
|
|
474
|
+
function useSheetsResetPassword() {
|
|
475
|
+
const queryClient = (0, import_react_query4.useQueryClient)();
|
|
476
|
+
const { config } = useSheetsContext();
|
|
477
|
+
return (0, import_react_query4.useMutation)({
|
|
478
|
+
mutationKey: ["sheets", "auth", "resetPassword"],
|
|
479
|
+
mutationFn: async (input) => {
|
|
480
|
+
const result = await executeAuthMutation(
|
|
481
|
+
config,
|
|
482
|
+
RESET_PASSWORD_MUTATION,
|
|
483
|
+
{
|
|
484
|
+
input: {
|
|
485
|
+
newPassword: input.newPassword,
|
|
486
|
+
resetToken: input.resetToken,
|
|
487
|
+
roleId: input.roleId
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
);
|
|
491
|
+
if (!result.resetPassword?.result) {
|
|
492
|
+
throw new Error("Failed to reset password. The link may have expired.");
|
|
493
|
+
}
|
|
494
|
+
return { success: true };
|
|
495
|
+
},
|
|
496
|
+
onSuccess: () => {
|
|
497
|
+
queryClient.invalidateQueries({ queryKey: ["sheets"] });
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// src/auth/ui/login-form.tsx
|
|
503
|
+
var import_react3 = require("react");
|
|
504
|
+
var import_react_form = require("@tanstack/react-form");
|
|
505
|
+
|
|
506
|
+
// src/auth/utils/schemas.ts
|
|
507
|
+
var import_zod = require("zod");
|
|
508
|
+
var passwordSchema = import_zod.z.string().min(8, "Password must be at least 8 characters").regex(
|
|
509
|
+
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]/,
|
|
510
|
+
"Password must contain uppercase, lowercase, number, and special character"
|
|
511
|
+
);
|
|
512
|
+
var emailSchema = import_zod.z.string().email("Please enter a valid email address");
|
|
513
|
+
var loginSchema = import_zod.z.object({
|
|
514
|
+
email: emailSchema,
|
|
515
|
+
password: import_zod.z.string().min(1, "Password is required"),
|
|
516
|
+
rememberMe: import_zod.z.boolean().optional()
|
|
517
|
+
});
|
|
518
|
+
var registerSchema = import_zod.z.object({
|
|
519
|
+
email: emailSchema,
|
|
520
|
+
password: import_zod.z.string().min(1, "Password is required"),
|
|
521
|
+
confirmPassword: import_zod.z.string().min(1, "Please confirm your password"),
|
|
522
|
+
rememberMe: import_zod.z.boolean().optional()
|
|
523
|
+
}).refine((data) => data.password === data.confirmPassword, {
|
|
524
|
+
message: "Passwords do not match",
|
|
525
|
+
path: ["confirmPassword"]
|
|
526
|
+
});
|
|
527
|
+
var forgotPasswordSchema = import_zod.z.object({
|
|
528
|
+
email: emailSchema
|
|
529
|
+
});
|
|
530
|
+
var resetPasswordSchema = import_zod.z.object({
|
|
531
|
+
password: passwordSchema,
|
|
532
|
+
confirmPassword: import_zod.z.string(),
|
|
533
|
+
token: import_zod.z.string().min(1, "Reset token is required")
|
|
534
|
+
}).refine((data) => data.password === data.confirmPassword, {
|
|
535
|
+
message: "Passwords do not match",
|
|
536
|
+
path: ["confirmPassword"]
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// src/auth/ui/login-form.tsx
|
|
540
|
+
var import_button2 = require("@constructive-io/ui/button");
|
|
541
|
+
var import_checkbox = require("@constructive-io/ui/checkbox");
|
|
542
|
+
|
|
543
|
+
// src/auth/ui/auth-error-alert.tsx
|
|
544
|
+
var import_lucide_react = require("lucide-react");
|
|
545
|
+
|
|
546
|
+
// src/utils/cn.ts
|
|
547
|
+
var import_clsx = require("clsx");
|
|
548
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
549
|
+
function cn(...inputs) {
|
|
550
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/auth/ui/auth-error-alert.tsx
|
|
554
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
555
|
+
function AuthErrorAlert({ error, className }) {
|
|
556
|
+
const hasError = Boolean(error);
|
|
557
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
558
|
+
"div",
|
|
559
|
+
{
|
|
560
|
+
role: "alert",
|
|
561
|
+
"aria-live": "polite",
|
|
562
|
+
"aria-hidden": !hasError,
|
|
563
|
+
className: cn(
|
|
564
|
+
"overflow-hidden transition-all duration-300 ease-out",
|
|
565
|
+
hasError ? "max-h-32" : "max-h-0",
|
|
566
|
+
className
|
|
567
|
+
),
|
|
568
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
569
|
+
"div",
|
|
570
|
+
{
|
|
571
|
+
className: cn(
|
|
572
|
+
"flex items-start gap-2.5 rounded-md px-3 py-2.5",
|
|
573
|
+
"bg-destructive/8 border border-destructive/20",
|
|
574
|
+
"text-destructive text-sm text-left",
|
|
575
|
+
"transition-opacity duration-200",
|
|
576
|
+
hasError ? "opacity-100" : "opacity-0"
|
|
577
|
+
),
|
|
578
|
+
children: [
|
|
579
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.AlertCircleIcon, { className: "mt-0.5 h-4 w-4 shrink-0" }),
|
|
580
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-pretty leading-snug", children: error })
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
)
|
|
584
|
+
}
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/auth/ui/auth-loading-button.tsx
|
|
589
|
+
var import_lucide_react2 = require("lucide-react");
|
|
590
|
+
var import_button = require("@constructive-io/ui/button");
|
|
591
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
592
|
+
function AuthLoadingButton({
|
|
593
|
+
children,
|
|
594
|
+
isLoading,
|
|
595
|
+
loadingText = "Please wait...",
|
|
596
|
+
disabled,
|
|
597
|
+
className,
|
|
598
|
+
...props
|
|
599
|
+
}) {
|
|
600
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_button.Button, { disabled: disabled || isLoading, className: cn("relative", className), ...props, children: [
|
|
601
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react2.LoaderIcon, { className: "mr-2 h-4 w-4 animate-spin" }),
|
|
602
|
+
isLoading ? loadingText : children
|
|
603
|
+
] });
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/auth/ui/form-field.tsx
|
|
607
|
+
var import_input = require("@constructive-io/ui/input");
|
|
608
|
+
var import_form_control = require("@constructive-io/ui/form-control");
|
|
609
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
610
|
+
function FormField({
|
|
611
|
+
field,
|
|
612
|
+
label,
|
|
613
|
+
placeholder,
|
|
614
|
+
type = "text",
|
|
615
|
+
className,
|
|
616
|
+
layout = "floating",
|
|
617
|
+
inputRef,
|
|
618
|
+
testId
|
|
619
|
+
}) {
|
|
620
|
+
const errors = field.state.meta.errors?.filter(Boolean) ?? [];
|
|
621
|
+
const hasError = errors.length > 0;
|
|
622
|
+
const errorMessage = errors[0];
|
|
623
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
624
|
+
import_form_control.FormControl,
|
|
625
|
+
{
|
|
626
|
+
label,
|
|
627
|
+
id: field.name,
|
|
628
|
+
layout,
|
|
629
|
+
error: hasError ? errorMessage : void 0,
|
|
630
|
+
className,
|
|
631
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
632
|
+
import_input.Input,
|
|
633
|
+
{
|
|
634
|
+
ref: inputRef,
|
|
635
|
+
name: field.name,
|
|
636
|
+
"data-testid": testId ?? field.name,
|
|
637
|
+
type,
|
|
638
|
+
placeholder,
|
|
639
|
+
value: field.state.value || "",
|
|
640
|
+
onChange: (e) => field.handleChange(e.target.value),
|
|
641
|
+
onBlur: field.handleBlur
|
|
642
|
+
}
|
|
643
|
+
)
|
|
644
|
+
}
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// src/auth/ui/login-form.tsx
|
|
649
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
650
|
+
function SheetsLoginForm({ onLogin, onShowForgot, onShowRegister, defaultEmail = "" }) {
|
|
651
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
652
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react3.useState)(false);
|
|
653
|
+
const passwordInputRef = (0, import_react3.useRef)(null);
|
|
654
|
+
const form = (0, import_react_form.useForm)({
|
|
655
|
+
defaultValues: {
|
|
656
|
+
email: defaultEmail,
|
|
657
|
+
password: "",
|
|
658
|
+
rememberMe: true
|
|
659
|
+
},
|
|
660
|
+
onSubmit: async ({ value }) => {
|
|
661
|
+
setError(null);
|
|
662
|
+
setIsSubmitting(true);
|
|
663
|
+
try {
|
|
664
|
+
const validatedData = loginSchema.parse(value);
|
|
665
|
+
await onLogin(validatedData);
|
|
666
|
+
} catch (err) {
|
|
667
|
+
setError(parseGraphQLError(err).message);
|
|
668
|
+
} finally {
|
|
669
|
+
setIsSubmitting(false);
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
validators: {
|
|
673
|
+
onChange: ({ value }) => {
|
|
674
|
+
const result = loginSchema.safeParse(value);
|
|
675
|
+
if (!result.success) {
|
|
676
|
+
return result.error.issues.map((issue) => issue.message).join(", ");
|
|
677
|
+
}
|
|
678
|
+
return void 0;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "space-y-5", children: [
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
684
|
+
"form",
|
|
685
|
+
{
|
|
686
|
+
onSubmit: (e) => {
|
|
687
|
+
e.preventDefault();
|
|
688
|
+
e.stopPropagation();
|
|
689
|
+
form.handleSubmit();
|
|
690
|
+
},
|
|
691
|
+
className: "space-y-4 px-8",
|
|
692
|
+
children: [
|
|
693
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AuthErrorAlert, { error }),
|
|
694
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
695
|
+
form.Field,
|
|
696
|
+
{
|
|
697
|
+
name: "email",
|
|
698
|
+
validators: {
|
|
699
|
+
onChange: ({ value }) => {
|
|
700
|
+
if (!value) return "Email is required";
|
|
701
|
+
if (!/\S+@\S+\.\S+/.test(value)) return "Please enter a valid email";
|
|
702
|
+
return void 0;
|
|
703
|
+
}
|
|
704
|
+
},
|
|
705
|
+
children: (field) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
706
|
+
FormField,
|
|
707
|
+
{
|
|
708
|
+
field,
|
|
709
|
+
label: "Email",
|
|
710
|
+
placeholder: "Enter your email",
|
|
711
|
+
type: "email"
|
|
712
|
+
}
|
|
713
|
+
)
|
|
714
|
+
}
|
|
715
|
+
),
|
|
716
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
717
|
+
form.Field,
|
|
718
|
+
{
|
|
719
|
+
name: "password",
|
|
720
|
+
validators: {
|
|
721
|
+
onChange: ({ value }) => {
|
|
722
|
+
if (!value) return "Password is required";
|
|
723
|
+
return void 0;
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
children: (field) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
727
|
+
FormField,
|
|
728
|
+
{
|
|
729
|
+
field,
|
|
730
|
+
label: "Password",
|
|
731
|
+
placeholder: "Enter your password",
|
|
732
|
+
type: "password",
|
|
733
|
+
inputRef: passwordInputRef
|
|
734
|
+
}
|
|
735
|
+
)
|
|
736
|
+
}
|
|
737
|
+
),
|
|
738
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(form.Field, { name: "rememberMe", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center space-x-2", children: [
|
|
739
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
740
|
+
import_checkbox.Checkbox,
|
|
741
|
+
{
|
|
742
|
+
id: "rememberMe",
|
|
743
|
+
checked: field.state.value,
|
|
744
|
+
onCheckedChange: (checked) => {
|
|
745
|
+
field.handleChange(checked === true);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
),
|
|
749
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
750
|
+
"label",
|
|
751
|
+
{
|
|
752
|
+
htmlFor: "rememberMe",
|
|
753
|
+
className: "text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
754
|
+
children: "Remember me"
|
|
755
|
+
}
|
|
756
|
+
)
|
|
757
|
+
] }) }),
|
|
758
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "space-y-3 pt-2", children: [
|
|
759
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
760
|
+
AuthLoadingButton,
|
|
761
|
+
{
|
|
762
|
+
type: "submit",
|
|
763
|
+
className: "w-full",
|
|
764
|
+
isLoading: isSubmitting,
|
|
765
|
+
disabled: isSubmitting,
|
|
766
|
+
"data-testid": "auth-login-submit",
|
|
767
|
+
children: "Sign In"
|
|
768
|
+
}
|
|
769
|
+
),
|
|
770
|
+
onShowForgot && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "text-center", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
771
|
+
import_button2.Button,
|
|
772
|
+
{
|
|
773
|
+
variant: "link",
|
|
774
|
+
className: "text-muted-foreground hover:text-foreground h-auto p-0 text-sm",
|
|
775
|
+
onClick: onShowForgot,
|
|
776
|
+
type: "button",
|
|
777
|
+
"data-testid": "auth-forgot-link",
|
|
778
|
+
children: "Forgot your password?"
|
|
779
|
+
}
|
|
780
|
+
) })
|
|
781
|
+
] })
|
|
782
|
+
]
|
|
783
|
+
}
|
|
784
|
+
),
|
|
785
|
+
onShowRegister && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "border-border/40 border-t pt-5", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "text-muted-foreground text-center text-sm", children: [
|
|
786
|
+
"Don't have an account?",
|
|
787
|
+
" ",
|
|
788
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
789
|
+
import_button2.Button,
|
|
790
|
+
{
|
|
791
|
+
variant: "link",
|
|
792
|
+
className: "text-primary hover:text-primary/80 h-auto p-0 font-medium",
|
|
793
|
+
onClick: onShowRegister,
|
|
794
|
+
type: "button",
|
|
795
|
+
children: "Sign up"
|
|
796
|
+
}
|
|
797
|
+
)
|
|
798
|
+
] }) })
|
|
799
|
+
] });
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/auth/ui/register-form.tsx
|
|
803
|
+
var import_react4 = require("react");
|
|
804
|
+
var import_react_form2 = require("@tanstack/react-form");
|
|
805
|
+
var import_button3 = require("@constructive-io/ui/button");
|
|
806
|
+
var import_checkbox2 = require("@constructive-io/ui/checkbox");
|
|
807
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
808
|
+
function SheetsRegisterForm({ onRegister, onShowLogin, defaultEmail = "" }) {
|
|
809
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
810
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react4.useState)(false);
|
|
811
|
+
const passwordInputRef = (0, import_react4.useRef)(null);
|
|
812
|
+
const form = (0, import_react_form2.useForm)({
|
|
813
|
+
defaultValues: {
|
|
814
|
+
email: defaultEmail,
|
|
815
|
+
password: "",
|
|
816
|
+
confirmPassword: "",
|
|
817
|
+
rememberMe: true
|
|
818
|
+
},
|
|
819
|
+
onSubmit: async ({ value }) => {
|
|
820
|
+
setError(null);
|
|
821
|
+
setIsSubmitting(true);
|
|
822
|
+
try {
|
|
823
|
+
const validatedData = registerSchema.parse(value);
|
|
824
|
+
await onRegister(validatedData);
|
|
825
|
+
} catch (err) {
|
|
826
|
+
setError(parseGraphQLError(err).message);
|
|
827
|
+
} finally {
|
|
828
|
+
setIsSubmitting(false);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-5", children: [
|
|
833
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
834
|
+
"form",
|
|
835
|
+
{
|
|
836
|
+
onSubmit: (e) => {
|
|
837
|
+
e.preventDefault();
|
|
838
|
+
e.stopPropagation();
|
|
839
|
+
form.handleSubmit();
|
|
840
|
+
},
|
|
841
|
+
className: "space-y-4 px-8 pb-2",
|
|
842
|
+
children: [
|
|
843
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AuthErrorAlert, { error }),
|
|
844
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(form.Field, { name: "email", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
845
|
+
FormField,
|
|
846
|
+
{
|
|
847
|
+
field,
|
|
848
|
+
label: "Email",
|
|
849
|
+
placeholder: "Enter your email",
|
|
850
|
+
type: "email"
|
|
851
|
+
}
|
|
852
|
+
) }),
|
|
853
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(form.Field, { name: "password", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
854
|
+
FormField,
|
|
855
|
+
{
|
|
856
|
+
field,
|
|
857
|
+
label: "Password",
|
|
858
|
+
placeholder: "Enter your password",
|
|
859
|
+
type: "password",
|
|
860
|
+
inputRef: passwordInputRef
|
|
861
|
+
}
|
|
862
|
+
) }),
|
|
863
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(form.Field, { name: "confirmPassword", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
864
|
+
FormField,
|
|
865
|
+
{
|
|
866
|
+
field,
|
|
867
|
+
label: "Confirm Password",
|
|
868
|
+
placeholder: "Confirm your password",
|
|
869
|
+
type: "password"
|
|
870
|
+
}
|
|
871
|
+
) }),
|
|
872
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(form.Field, { name: "rememberMe", children: (field) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-2", children: [
|
|
873
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
874
|
+
import_checkbox2.Checkbox,
|
|
875
|
+
{
|
|
876
|
+
id: "rememberMe",
|
|
877
|
+
checked: field.state.value,
|
|
878
|
+
onCheckedChange: (checked) => {
|
|
879
|
+
field.handleChange(checked === true);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
),
|
|
883
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
884
|
+
"label",
|
|
885
|
+
{
|
|
886
|
+
htmlFor: "rememberMe",
|
|
887
|
+
className: "text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
888
|
+
children: "Remember me"
|
|
889
|
+
}
|
|
890
|
+
)
|
|
891
|
+
] }) }),
|
|
892
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "pt-2", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
893
|
+
AuthLoadingButton,
|
|
894
|
+
{
|
|
895
|
+
type: "submit",
|
|
896
|
+
className: "w-full",
|
|
897
|
+
isLoading: isSubmitting,
|
|
898
|
+
disabled: isSubmitting,
|
|
899
|
+
"data-testid": "auth-signup-submit",
|
|
900
|
+
children: "Create Account"
|
|
901
|
+
}
|
|
902
|
+
) })
|
|
903
|
+
]
|
|
904
|
+
}
|
|
905
|
+
),
|
|
906
|
+
onShowLogin && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "border-border/40 border-t pt-5", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "text-muted-foreground text-center text-sm", children: [
|
|
907
|
+
"Already have an account?",
|
|
908
|
+
" ",
|
|
909
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
910
|
+
import_button3.Button,
|
|
911
|
+
{
|
|
912
|
+
variant: "link",
|
|
913
|
+
className: "text-primary hover:text-primary/80 h-auto p-0 font-medium",
|
|
914
|
+
onClick: onShowLogin,
|
|
915
|
+
type: "button",
|
|
916
|
+
"data-testid": "auth-signup-login-link",
|
|
917
|
+
children: "Sign in"
|
|
918
|
+
}
|
|
919
|
+
)
|
|
920
|
+
] }) })
|
|
921
|
+
] });
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// src/auth/ui/forgot-password-form.tsx
|
|
925
|
+
var import_react5 = require("react");
|
|
926
|
+
var import_react_form3 = require("@tanstack/react-form");
|
|
927
|
+
var import_lucide_react3 = require("lucide-react");
|
|
928
|
+
var import_button4 = require("@constructive-io/ui/button");
|
|
929
|
+
|
|
930
|
+
// src/auth/ui/auth-screen-header.tsx
|
|
931
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
932
|
+
function AuthScreenHeader({
|
|
933
|
+
title,
|
|
934
|
+
description,
|
|
935
|
+
logo,
|
|
936
|
+
appName,
|
|
937
|
+
showLogo = true,
|
|
938
|
+
className
|
|
939
|
+
}) {
|
|
940
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: cn("space-y-4 text-center", className), children: [
|
|
941
|
+
showLogo && logo ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "flex items-center justify-center", children: logo }) : null,
|
|
942
|
+
appName ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-primary text-[15px] font-semibold tracking-tight", children: appName }) : null,
|
|
943
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-1.5", children: [
|
|
944
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
945
|
+
"h2",
|
|
946
|
+
{
|
|
947
|
+
className: "from-foreground via-foreground to-foreground/70 bg-linear-to-br bg-clip-text text-xl\n font-semibold tracking-tight text-transparent",
|
|
948
|
+
children: title
|
|
949
|
+
}
|
|
950
|
+
),
|
|
951
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-muted-foreground text-[13px] leading-relaxed", children: description }) : null
|
|
952
|
+
] })
|
|
953
|
+
] });
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// src/auth/ui/forgot-password-form.tsx
|
|
957
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
958
|
+
function SheetsForgotPasswordForm({ onForgotPassword, onShowLogin }) {
|
|
959
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
960
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react5.useState)(false);
|
|
961
|
+
const [isSuccess, setIsSuccess] = (0, import_react5.useState)(false);
|
|
962
|
+
const form = (0, import_react_form3.useForm)({
|
|
963
|
+
defaultValues: {
|
|
964
|
+
email: ""
|
|
965
|
+
},
|
|
966
|
+
onSubmit: async ({ value }) => {
|
|
967
|
+
setError(null);
|
|
968
|
+
setIsSubmitting(true);
|
|
969
|
+
try {
|
|
970
|
+
const validatedData = forgotPasswordSchema.parse(value);
|
|
971
|
+
await onForgotPassword(validatedData);
|
|
972
|
+
setIsSuccess(true);
|
|
973
|
+
} catch (err) {
|
|
974
|
+
setError(parseGraphQLError(err).message);
|
|
975
|
+
} finally {
|
|
976
|
+
setIsSubmitting(false);
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
validators: {
|
|
980
|
+
onChange: ({ value }) => {
|
|
981
|
+
const result = forgotPasswordSchema.safeParse(value);
|
|
982
|
+
if (!result.success) {
|
|
983
|
+
return result.error.issues.map((issue) => issue.message).join(", ");
|
|
984
|
+
}
|
|
985
|
+
return void 0;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
if (isSuccess) {
|
|
990
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-5 text-center", children: [
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "bg-success/10 flex h-12 w-12 items-center justify-center rounded-full", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.CheckCircleIcon, { className: "text-success h-6 w-6" }) }) }),
|
|
992
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-1.5", children: [
|
|
993
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { className: "text-lg font-semibold", children: "Check your email" }),
|
|
994
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "text-muted-foreground text-sm", children: "We've sent a password reset link to your email address." })
|
|
995
|
+
] }),
|
|
996
|
+
onShowLogin && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "pt-1", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_button4.Button, { variant: "outline", type: "button", onClick: onShowLogin, className: "w-full", children: "Back to sign in" }) })
|
|
997
|
+
] });
|
|
998
|
+
}
|
|
999
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-5", children: [
|
|
1000
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthScreenHeader, { title: "Reset your password", description: "We'll send you a password reset link" }),
|
|
1001
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1002
|
+
"form",
|
|
1003
|
+
{
|
|
1004
|
+
onSubmit: (e) => {
|
|
1005
|
+
e.preventDefault();
|
|
1006
|
+
e.stopPropagation();
|
|
1007
|
+
form.handleSubmit();
|
|
1008
|
+
},
|
|
1009
|
+
className: "space-y-4 px-8",
|
|
1010
|
+
children: [
|
|
1011
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthErrorAlert, { error }),
|
|
1012
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1013
|
+
form.Field,
|
|
1014
|
+
{
|
|
1015
|
+
name: "email",
|
|
1016
|
+
validators: {
|
|
1017
|
+
onChange: ({ value }) => {
|
|
1018
|
+
if (!value) return "Email is required";
|
|
1019
|
+
if (!/\S+@\S+\.\S+/.test(value)) return "Please enter a valid email";
|
|
1020
|
+
return void 0;
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
children: (field) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1024
|
+
FormField,
|
|
1025
|
+
{
|
|
1026
|
+
field,
|
|
1027
|
+
label: "Email",
|
|
1028
|
+
placeholder: "Enter your email",
|
|
1029
|
+
type: "email"
|
|
1030
|
+
}
|
|
1031
|
+
)
|
|
1032
|
+
}
|
|
1033
|
+
),
|
|
1034
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "pt-2", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1035
|
+
AuthLoadingButton,
|
|
1036
|
+
{
|
|
1037
|
+
type: "submit",
|
|
1038
|
+
className: "w-full",
|
|
1039
|
+
isLoading: isSubmitting,
|
|
1040
|
+
disabled: isSubmitting,
|
|
1041
|
+
"data-testid": "auth-forgot-submit",
|
|
1042
|
+
children: "Send Reset Link"
|
|
1043
|
+
}
|
|
1044
|
+
) })
|
|
1045
|
+
]
|
|
1046
|
+
}
|
|
1047
|
+
),
|
|
1048
|
+
onShowLogin && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "text-muted-foreground text-center text-sm", children: [
|
|
1049
|
+
"Remember your password?",
|
|
1050
|
+
" ",
|
|
1051
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1052
|
+
import_button4.Button,
|
|
1053
|
+
{
|
|
1054
|
+
variant: "link",
|
|
1055
|
+
className: "text-primary hover:text-primary/80 h-auto p-0 font-medium",
|
|
1056
|
+
onClick: onShowLogin,
|
|
1057
|
+
type: "button",
|
|
1058
|
+
children: "Sign in"
|
|
1059
|
+
}
|
|
1060
|
+
)
|
|
1061
|
+
] })
|
|
1062
|
+
] });
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// src/auth/ui/reset-password-form.tsx
|
|
1066
|
+
var React = __toESM(require("react"), 1);
|
|
1067
|
+
var import_react_form4 = require("@tanstack/react-form");
|
|
1068
|
+
var import_lucide_react4 = require("lucide-react");
|
|
1069
|
+
var import_button5 = require("@constructive-io/ui/button");
|
|
1070
|
+
|
|
1071
|
+
// src/auth/utils/validators.ts
|
|
1072
|
+
function getPasswordStrength(password) {
|
|
1073
|
+
let score = 0;
|
|
1074
|
+
if (password.length >= 8) score++;
|
|
1075
|
+
if (/[a-z]/.test(password)) score++;
|
|
1076
|
+
if (/[A-Z]/.test(password)) score++;
|
|
1077
|
+
if (/\d/.test(password)) score++;
|
|
1078
|
+
if (/[@$!%*?&]/.test(password)) score++;
|
|
1079
|
+
return score;
|
|
1080
|
+
}
|
|
1081
|
+
function getPasswordStrengthLabel(score) {
|
|
1082
|
+
const labels = ["Very Weak", "Weak", "Fair", "Good", "Strong"];
|
|
1083
|
+
return labels[score - 1] || "Very Weak";
|
|
1084
|
+
}
|
|
1085
|
+
function getPasswordStrengthColor(score) {
|
|
1086
|
+
const colors = ["bg-red-500", "bg-orange-500", "bg-yellow-500", "bg-blue-500", "bg-green-500"];
|
|
1087
|
+
return colors[score - 1] || "bg-red-500";
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// src/auth/ui/password-strength.tsx
|
|
1091
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1092
|
+
function PasswordStrength({ password, className }) {
|
|
1093
|
+
const strength = getPasswordStrength(password);
|
|
1094
|
+
const label = getPasswordStrengthLabel(strength);
|
|
1095
|
+
const colorClass = getPasswordStrengthColor(strength);
|
|
1096
|
+
if (!password) {
|
|
1097
|
+
return null;
|
|
1098
|
+
}
|
|
1099
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: cn("space-y-2", className), children: [
|
|
1100
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex space-x-1", children: [...Array(5)].map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: cn("h-2 w-full rounded transition-colors", i < strength ? colorClass : "bg-muted") }, i)) }),
|
|
1101
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("p", { className: "text-muted-foreground text-sm", children: [
|
|
1102
|
+
"Password strength:",
|
|
1103
|
+
" ",
|
|
1104
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1105
|
+
"span",
|
|
1106
|
+
{
|
|
1107
|
+
className: cn("font-medium", {
|
|
1108
|
+
"text-red-600": strength <= 2,
|
|
1109
|
+
"text-yellow-600": strength === 3,
|
|
1110
|
+
"text-blue-600": strength === 4,
|
|
1111
|
+
"text-green-600": strength === 5
|
|
1112
|
+
}),
|
|
1113
|
+
children: label
|
|
1114
|
+
}
|
|
1115
|
+
)
|
|
1116
|
+
] })
|
|
1117
|
+
] });
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// src/auth/ui/reset-password-form.tsx
|
|
1121
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1122
|
+
function SheetsResetPasswordForm({
|
|
1123
|
+
resetToken,
|
|
1124
|
+
roleId,
|
|
1125
|
+
onResetPassword,
|
|
1126
|
+
onShowLogin
|
|
1127
|
+
}) {
|
|
1128
|
+
const [error, setError] = React.useState(null);
|
|
1129
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
1130
|
+
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
1131
|
+
const form = (0, import_react_form4.useForm)({
|
|
1132
|
+
defaultValues: {
|
|
1133
|
+
password: "",
|
|
1134
|
+
confirmPassword: "",
|
|
1135
|
+
token: resetToken
|
|
1136
|
+
},
|
|
1137
|
+
onSubmit: async ({ value }) => {
|
|
1138
|
+
setError(null);
|
|
1139
|
+
setIsSubmitting(true);
|
|
1140
|
+
try {
|
|
1141
|
+
const validatedData = resetPasswordSchema.parse(value);
|
|
1142
|
+
await onResetPassword({
|
|
1143
|
+
newPassword: validatedData.password,
|
|
1144
|
+
resetToken: validatedData.token,
|
|
1145
|
+
roleId
|
|
1146
|
+
});
|
|
1147
|
+
setIsSuccess(true);
|
|
1148
|
+
} catch (err) {
|
|
1149
|
+
setError(parseGraphQLError(err).message);
|
|
1150
|
+
} finally {
|
|
1151
|
+
setIsSubmitting(false);
|
|
1152
|
+
}
|
|
1153
|
+
},
|
|
1154
|
+
validators: {
|
|
1155
|
+
onChange: ({ value }) => {
|
|
1156
|
+
const result = resetPasswordSchema.safeParse(value);
|
|
1157
|
+
if (!result.success) {
|
|
1158
|
+
return result.error.issues.map((issue) => issue.message).join(", ");
|
|
1159
|
+
}
|
|
1160
|
+
return void 0;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
if (isSuccess) {
|
|
1165
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "space-y-5 text-center", children: [
|
|
1166
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "bg-success/10 flex h-12 w-12 items-center justify-center rounded-full", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react4.CheckCircleIcon, { className: "text-success h-6 w-6" }) }) }),
|
|
1167
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "space-y-1.5", children: [
|
|
1168
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("h3", { className: "text-lg font-semibold", children: "Password reset successful" }),
|
|
1169
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "text-muted-foreground text-sm", children: "Your password has been reset successfully. You can now sign in with your new password." })
|
|
1170
|
+
] }),
|
|
1171
|
+
onShowLogin && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "pt-1", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_button5.Button, { type: "button", onClick: onShowLogin, className: "w-full", children: "Sign in" }) })
|
|
1172
|
+
] });
|
|
1173
|
+
}
|
|
1174
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "space-y-5", children: [
|
|
1175
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AuthScreenHeader, { title: "Set a new password", description: "Enter your new password below" }),
|
|
1176
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1177
|
+
"form",
|
|
1178
|
+
{
|
|
1179
|
+
onSubmit: (e) => {
|
|
1180
|
+
e.preventDefault();
|
|
1181
|
+
e.stopPropagation();
|
|
1182
|
+
form.handleSubmit();
|
|
1183
|
+
},
|
|
1184
|
+
className: "space-y-4 px-8",
|
|
1185
|
+
children: [
|
|
1186
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AuthErrorAlert, { error }),
|
|
1187
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1188
|
+
form.Field,
|
|
1189
|
+
{
|
|
1190
|
+
name: "password",
|
|
1191
|
+
validators: {
|
|
1192
|
+
onChange: ({ value }) => {
|
|
1193
|
+
if (!value) return "Password is required";
|
|
1194
|
+
if (value.length < 8) return "Password must be at least 8 characters";
|
|
1195
|
+
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]/.test(value)) {
|
|
1196
|
+
return "Password must contain uppercase, lowercase, number, and special character";
|
|
1197
|
+
}
|
|
1198
|
+
return void 0;
|
|
1199
|
+
}
|
|
1200
|
+
},
|
|
1201
|
+
children: (field) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "space-y-2", children: [
|
|
1202
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1203
|
+
FormField,
|
|
1204
|
+
{
|
|
1205
|
+
field,
|
|
1206
|
+
label: "New Password",
|
|
1207
|
+
placeholder: "Enter your new password",
|
|
1208
|
+
type: "password"
|
|
1209
|
+
}
|
|
1210
|
+
),
|
|
1211
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PasswordStrength, { password: field.state.value })
|
|
1212
|
+
] })
|
|
1213
|
+
}
|
|
1214
|
+
),
|
|
1215
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1216
|
+
form.Field,
|
|
1217
|
+
{
|
|
1218
|
+
name: "confirmPassword",
|
|
1219
|
+
validators: {
|
|
1220
|
+
onChange: ({ value }) => {
|
|
1221
|
+
if (!value) return "Please confirm your password";
|
|
1222
|
+
const password = form.getFieldValue("password");
|
|
1223
|
+
if (value !== password) return "Passwords do not match";
|
|
1224
|
+
return void 0;
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1227
|
+
children: (field) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1228
|
+
FormField,
|
|
1229
|
+
{
|
|
1230
|
+
field,
|
|
1231
|
+
label: "Confirm New Password",
|
|
1232
|
+
placeholder: "Confirm your new password",
|
|
1233
|
+
type: "password"
|
|
1234
|
+
}
|
|
1235
|
+
)
|
|
1236
|
+
}
|
|
1237
|
+
),
|
|
1238
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "pt-2", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1239
|
+
AuthLoadingButton,
|
|
1240
|
+
{
|
|
1241
|
+
type: "submit",
|
|
1242
|
+
className: "w-full",
|
|
1243
|
+
isLoading: isSubmitting,
|
|
1244
|
+
disabled: !form.state.canSubmit || isSubmitting,
|
|
1245
|
+
"data-testid": "auth-reset-submit",
|
|
1246
|
+
children: "Reset Password"
|
|
1247
|
+
}
|
|
1248
|
+
) })
|
|
1249
|
+
]
|
|
1250
|
+
}
|
|
1251
|
+
),
|
|
1252
|
+
onShowLogin && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "text-muted-foreground text-center text-sm", children: [
|
|
1253
|
+
"Remember your password?",
|
|
1254
|
+
" ",
|
|
1255
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1256
|
+
import_button5.Button,
|
|
1257
|
+
{
|
|
1258
|
+
variant: "link",
|
|
1259
|
+
className: "text-primary hover:text-primary/80 h-auto p-0 font-medium",
|
|
1260
|
+
onClick: onShowLogin,
|
|
1261
|
+
type: "button",
|
|
1262
|
+
children: "Sign in"
|
|
1263
|
+
}
|
|
1264
|
+
)
|
|
1265
|
+
] })
|
|
1266
|
+
] });
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
// src/auth/ui/auth-screen-layout.tsx
|
|
1270
|
+
var import_card = require("@constructive-io/ui/card");
|
|
1271
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1272
|
+
function AuthScreenLayout({
|
|
1273
|
+
children,
|
|
1274
|
+
fill = "parent",
|
|
1275
|
+
className
|
|
1276
|
+
}) {
|
|
1277
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1278
|
+
"div",
|
|
1279
|
+
{
|
|
1280
|
+
className: cn(
|
|
1281
|
+
"bg-background relative flex flex-col",
|
|
1282
|
+
fill === "viewport" ? "min-h-dvh w-dvw" : "h-full w-full",
|
|
1283
|
+
className
|
|
1284
|
+
),
|
|
1285
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex flex-1 items-center justify-center p-6", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "relative z-10 w-full max-w-md", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_card.Card, { className: "overflow-hidden border-border/80", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_card.CardContent, { className: "space-y-2 pt-6", children }) }) }) })
|
|
1286
|
+
}
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// src/auth/auth-gate.tsx
|
|
1291
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1292
|
+
var AUTH_CONTENT = {
|
|
1293
|
+
login: {
|
|
1294
|
+
title: "Welcome back",
|
|
1295
|
+
description: "Sign in to your account"
|
|
1296
|
+
},
|
|
1297
|
+
register: {
|
|
1298
|
+
title: "Create an account",
|
|
1299
|
+
description: "Get started with your free account"
|
|
1300
|
+
},
|
|
1301
|
+
forgot: {
|
|
1302
|
+
title: "Reset your password",
|
|
1303
|
+
description: "We'll send you a password reset link"
|
|
1304
|
+
},
|
|
1305
|
+
reset: {
|
|
1306
|
+
title: "Set a new password",
|
|
1307
|
+
description: "Enter your new password below"
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
function SheetsAuthGate({
|
|
1311
|
+
children,
|
|
1312
|
+
loginComponent: CustomLoginComponent,
|
|
1313
|
+
resetToken,
|
|
1314
|
+
roleId,
|
|
1315
|
+
logo,
|
|
1316
|
+
appName,
|
|
1317
|
+
showLogo
|
|
1318
|
+
}) {
|
|
1319
|
+
const { config } = useSheetsContext();
|
|
1320
|
+
const isAuthenticated = useSheetsStore((s) => s.isAuthenticated);
|
|
1321
|
+
if (config.auth.mode === "embedded") {
|
|
1322
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children });
|
|
1323
|
+
}
|
|
1324
|
+
if (isAuthenticated) {
|
|
1325
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children });
|
|
1326
|
+
}
|
|
1327
|
+
if (CustomLoginComponent) {
|
|
1328
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CustomLoginComponent, {});
|
|
1329
|
+
}
|
|
1330
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1331
|
+
StandaloneAuthUI,
|
|
1332
|
+
{
|
|
1333
|
+
resetToken,
|
|
1334
|
+
roleId,
|
|
1335
|
+
logo,
|
|
1336
|
+
appName,
|
|
1337
|
+
showLogo
|
|
1338
|
+
}
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
function StandaloneAuthUI({ resetToken, roleId, logo, appName, showLogo }) {
|
|
1342
|
+
const initialMode = resetToken ? "reset" : "login";
|
|
1343
|
+
const [mode, setMode] = (0, import_react6.useState)(initialMode);
|
|
1344
|
+
const loginMutation = useSheetsLogin();
|
|
1345
|
+
const registerMutation = useSheetsRegister();
|
|
1346
|
+
const forgotPasswordMutation = useSheetsForgotPassword();
|
|
1347
|
+
const resetPasswordMutation = useSheetsResetPassword();
|
|
1348
|
+
const { title, description } = AUTH_CONTENT[mode];
|
|
1349
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(AuthScreenLayout, { fill: "parent", logo, appName, showLogo, children: [
|
|
1350
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1351
|
+
AuthScreenHeader,
|
|
1352
|
+
{
|
|
1353
|
+
title,
|
|
1354
|
+
description,
|
|
1355
|
+
logo,
|
|
1356
|
+
appName,
|
|
1357
|
+
showLogo
|
|
1358
|
+
}
|
|
1359
|
+
),
|
|
1360
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { children: [
|
|
1361
|
+
mode === "login" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1362
|
+
SheetsLoginForm,
|
|
1363
|
+
{
|
|
1364
|
+
onLogin: (credentials) => loginMutation.mutateAsync(credentials).then(() => {
|
|
1365
|
+
}),
|
|
1366
|
+
onShowForgot: () => setMode("forgot"),
|
|
1367
|
+
onShowRegister: () => setMode("register")
|
|
1368
|
+
}
|
|
1369
|
+
),
|
|
1370
|
+
mode === "register" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1371
|
+
SheetsRegisterForm,
|
|
1372
|
+
{
|
|
1373
|
+
onRegister: (data) => registerMutation.mutateAsync(data),
|
|
1374
|
+
onShowLogin: () => setMode("login")
|
|
1375
|
+
}
|
|
1376
|
+
),
|
|
1377
|
+
mode === "forgot" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1378
|
+
SheetsForgotPasswordForm,
|
|
1379
|
+
{
|
|
1380
|
+
onForgotPassword: (data) => forgotPasswordMutation.mutateAsync(data),
|
|
1381
|
+
onShowLogin: () => setMode("login")
|
|
1382
|
+
}
|
|
1383
|
+
),
|
|
1384
|
+
mode === "reset" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1385
|
+
SheetsResetPasswordForm,
|
|
1386
|
+
{
|
|
1387
|
+
resetToken: resetToken || "",
|
|
1388
|
+
roleId,
|
|
1389
|
+
onResetPassword: (input) => resetPasswordMutation.mutateAsync(input),
|
|
1390
|
+
onShowLogin: () => setMode("login")
|
|
1391
|
+
}
|
|
1392
|
+
)
|
|
1393
|
+
] })
|
|
1394
|
+
] });
|
|
1395
|
+
}
|
|
1396
|
+
//# sourceMappingURL=auth.cjs.map
|