@insforge/nextjs 0.6.7 → 0.6.9
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/index.d.mts +3 -11
- package/dist/index.d.ts +3 -11
- package/dist/index.js +119 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -240
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -57,9 +57,6 @@ interface SignUpProps {
|
|
|
57
57
|
passwordPlaceholder?: string;
|
|
58
58
|
submitButtonText?: string;
|
|
59
59
|
loadingButtonText?: string;
|
|
60
|
-
verifyButtonText?: string;
|
|
61
|
-
loadingVerifyButtonText?: string;
|
|
62
|
-
verifiedButtonText?: string;
|
|
63
60
|
signInText?: string;
|
|
64
61
|
signInLinkText?: string;
|
|
65
62
|
signInUrl?: string;
|
|
@@ -87,7 +84,7 @@ interface ConditionalProps {
|
|
|
87
84
|
type OAuthProvider = 'google' | 'github' | 'discord' | 'facebook' | 'linkedin' | 'instagram' | 'tiktok' | 'apple' | 'x' | 'spotify' | 'microsoft';
|
|
88
85
|
interface OAuthProviderConfig {
|
|
89
86
|
name: string;
|
|
90
|
-
svg:
|
|
87
|
+
svg: React.ReactElement;
|
|
91
88
|
className: string;
|
|
92
89
|
}
|
|
93
90
|
|
|
@@ -101,11 +98,6 @@ interface InsforgeContextValue {
|
|
|
101
98
|
signUp: (email: string, password: string) => Promise<void>;
|
|
102
99
|
signOut: () => Promise<void>;
|
|
103
100
|
updateUser: (data: Partial<InsforgeUser>) => Promise<void>;
|
|
104
|
-
sendVerificationCode: (email: string, type: 'signup' | 'signin') => Promise<void>;
|
|
105
|
-
verifySignUpCode: (email: string, password: string, code: string) => Promise<void>;
|
|
106
|
-
verifySignInCode: (email: string, code: string) => Promise<void>;
|
|
107
|
-
oauthProviders: OAuthProvider[];
|
|
108
|
-
isConfigLoaded: boolean;
|
|
109
101
|
baseUrl: string;
|
|
110
102
|
}
|
|
111
103
|
interface InsforgeProviderProps {
|
|
@@ -145,7 +137,7 @@ declare function useOAuthProviders(): {
|
|
|
145
137
|
|
|
146
138
|
declare function SignIn({ afterSignInUrl, appearance, title, subtitle, emailLabel, emailPlaceholder, passwordLabel, passwordPlaceholder, forgotPasswordText, submitButtonText, loadingButtonText, signUpText, signUpLinkText, signUpUrl, dividerText, onSuccess, onError, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
147
139
|
|
|
148
|
-
declare function SignUp({ afterSignUpUrl, appearance, title, subtitle, emailLabel, emailPlaceholder, passwordLabel, passwordPlaceholder, submitButtonText, loadingButtonText,
|
|
140
|
+
declare function SignUp({ afterSignUpUrl, appearance, title, subtitle, emailLabel, emailPlaceholder, passwordLabel, passwordPlaceholder, submitButtonText, loadingButtonText, signInText, signInLinkText, signInUrl, dividerText, onSuccess, onError, }: SignUpProps): react_jsx_runtime.JSX.Element;
|
|
149
141
|
|
|
150
142
|
declare function UserButton({ afterSignOutUrl, mode, appearance, }: UserButtonProps): react_jsx_runtime.JSX.Element | null;
|
|
151
143
|
|
|
@@ -153,7 +145,7 @@ declare function SignedIn({ children }: ConditionalProps): react_jsx_runtime.JSX
|
|
|
153
145
|
|
|
154
146
|
declare function SignedOut({ children }: ConditionalProps): react_jsx_runtime.JSX.Element | null;
|
|
155
147
|
|
|
156
|
-
declare function Protect({ children, fallback, redirectTo, condition, }: ProtectProps): string | number | bigint | true | Iterable<react.ReactNode> | Promise<react.
|
|
148
|
+
declare function Protect({ children, fallback, redirectTo, condition, }: ProtectProps): string | number | bigint | true | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
157
149
|
|
|
158
150
|
interface AuthContainerProps {
|
|
159
151
|
children: ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -57,9 +57,6 @@ interface SignUpProps {
|
|
|
57
57
|
passwordPlaceholder?: string;
|
|
58
58
|
submitButtonText?: string;
|
|
59
59
|
loadingButtonText?: string;
|
|
60
|
-
verifyButtonText?: string;
|
|
61
|
-
loadingVerifyButtonText?: string;
|
|
62
|
-
verifiedButtonText?: string;
|
|
63
60
|
signInText?: string;
|
|
64
61
|
signInLinkText?: string;
|
|
65
62
|
signInUrl?: string;
|
|
@@ -87,7 +84,7 @@ interface ConditionalProps {
|
|
|
87
84
|
type OAuthProvider = 'google' | 'github' | 'discord' | 'facebook' | 'linkedin' | 'instagram' | 'tiktok' | 'apple' | 'x' | 'spotify' | 'microsoft';
|
|
88
85
|
interface OAuthProviderConfig {
|
|
89
86
|
name: string;
|
|
90
|
-
svg:
|
|
87
|
+
svg: React.ReactElement;
|
|
91
88
|
className: string;
|
|
92
89
|
}
|
|
93
90
|
|
|
@@ -101,11 +98,6 @@ interface InsforgeContextValue {
|
|
|
101
98
|
signUp: (email: string, password: string) => Promise<void>;
|
|
102
99
|
signOut: () => Promise<void>;
|
|
103
100
|
updateUser: (data: Partial<InsforgeUser>) => Promise<void>;
|
|
104
|
-
sendVerificationCode: (email: string, type: 'signup' | 'signin') => Promise<void>;
|
|
105
|
-
verifySignUpCode: (email: string, password: string, code: string) => Promise<void>;
|
|
106
|
-
verifySignInCode: (email: string, code: string) => Promise<void>;
|
|
107
|
-
oauthProviders: OAuthProvider[];
|
|
108
|
-
isConfigLoaded: boolean;
|
|
109
101
|
baseUrl: string;
|
|
110
102
|
}
|
|
111
103
|
interface InsforgeProviderProps {
|
|
@@ -145,7 +137,7 @@ declare function useOAuthProviders(): {
|
|
|
145
137
|
|
|
146
138
|
declare function SignIn({ afterSignInUrl, appearance, title, subtitle, emailLabel, emailPlaceholder, passwordLabel, passwordPlaceholder, forgotPasswordText, submitButtonText, loadingButtonText, signUpText, signUpLinkText, signUpUrl, dividerText, onSuccess, onError, }: SignInProps): react_jsx_runtime.JSX.Element;
|
|
147
139
|
|
|
148
|
-
declare function SignUp({ afterSignUpUrl, appearance, title, subtitle, emailLabel, emailPlaceholder, passwordLabel, passwordPlaceholder, submitButtonText, loadingButtonText,
|
|
140
|
+
declare function SignUp({ afterSignUpUrl, appearance, title, subtitle, emailLabel, emailPlaceholder, passwordLabel, passwordPlaceholder, submitButtonText, loadingButtonText, signInText, signInLinkText, signInUrl, dividerText, onSuccess, onError, }: SignUpProps): react_jsx_runtime.JSX.Element;
|
|
149
141
|
|
|
150
142
|
declare function UserButton({ afterSignOutUrl, mode, appearance, }: UserButtonProps): react_jsx_runtime.JSX.Element | null;
|
|
151
143
|
|
|
@@ -153,7 +145,7 @@ declare function SignedIn({ children }: ConditionalProps): react_jsx_runtime.JSX
|
|
|
153
145
|
|
|
154
146
|
declare function SignedOut({ children }: ConditionalProps): react_jsx_runtime.JSX.Element | null;
|
|
155
147
|
|
|
156
|
-
declare function Protect({ children, fallback, redirectTo, condition, }: ProtectProps): string | number | bigint | true | Iterable<react.ReactNode> | Promise<react.
|
|
148
|
+
declare function Protect({ children, fallback, redirectTo, condition, }: ProtectProps): string | number | bigint | true | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
157
149
|
|
|
158
150
|
interface AuthContainerProps {
|
|
159
151
|
children: ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -70,20 +70,6 @@ var import_react = require("react");
|
|
|
70
70
|
var import_sdk = require("@insforge/sdk");
|
|
71
71
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
72
|
var InsforgeContext = (0, import_react.createContext)(void 0);
|
|
73
|
-
async function fetchOAuthProviders(baseUrl) {
|
|
74
|
-
try {
|
|
75
|
-
const response = await fetch(`${baseUrl}/api/auth/oauth/configs`);
|
|
76
|
-
if (!response.ok) return [];
|
|
77
|
-
const result = await response.json();
|
|
78
|
-
if (result?.data && Array.isArray(result.data)) {
|
|
79
|
-
return result.data.map((config) => config.provider);
|
|
80
|
-
}
|
|
81
|
-
return [];
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.warn("Failed to fetch OAuth configs:", error);
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
73
|
function getTokenFromSDK() {
|
|
88
74
|
console.log("[InsforgeProvider] Getting token from SDK");
|
|
89
75
|
if (typeof window === "undefined") return null;
|
|
@@ -127,18 +113,8 @@ function InsforgeProvider({
|
|
|
127
113
|
const [user, setUser] = (0, import_react.useState)(null);
|
|
128
114
|
const [session, setSession] = (0, import_react.useState)(null);
|
|
129
115
|
const [isLoaded, setIsLoaded] = (0, import_react.useState)(false);
|
|
130
|
-
const
|
|
131
|
-
const [isConfigLoaded, setIsConfigLoaded] = (0, import_react.useState)(false);
|
|
132
|
-
const refreshIntervalRef = (0, import_react.useRef)();
|
|
116
|
+
const refreshIntervalRef = (0, import_react.useRef)(null);
|
|
133
117
|
const [insforge] = (0, import_react.useState)(() => (0, import_sdk.createClient)({ baseUrl }));
|
|
134
|
-
(0, import_react.useEffect)(() => {
|
|
135
|
-
async function loadConfig() {
|
|
136
|
-
const providers = await fetchOAuthProviders(baseUrl);
|
|
137
|
-
setOauthProviders(providers);
|
|
138
|
-
setIsConfigLoaded(true);
|
|
139
|
-
}
|
|
140
|
-
loadConfig();
|
|
141
|
-
}, [baseUrl]);
|
|
142
118
|
const loadAuthState = (0, import_react.useCallback)(async () => {
|
|
143
119
|
try {
|
|
144
120
|
const token = getTokenFromSDK();
|
|
@@ -338,59 +314,6 @@ function InsforgeProvider({
|
|
|
338
314
|
},
|
|
339
315
|
[user, onAuthChange, insforge]
|
|
340
316
|
);
|
|
341
|
-
const sendVerificationCode = (0, import_react.useCallback)(
|
|
342
|
-
async (email, type) => {
|
|
343
|
-
console.log(`[Verification] Sending ${type} code to ${email}`);
|
|
344
|
-
console.log("[Verification] Dummy code: 123456");
|
|
345
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
346
|
-
},
|
|
347
|
-
[insforge]
|
|
348
|
-
);
|
|
349
|
-
const verifySignUpCode = (0, import_react.useCallback)(
|
|
350
|
-
async (email, password, code) => {
|
|
351
|
-
if (code !== "123456") {
|
|
352
|
-
throw new Error("Invalid verification code");
|
|
353
|
-
}
|
|
354
|
-
const sdkResult = await insforge.auth.signUp({ email, password });
|
|
355
|
-
if (sdkResult.data) {
|
|
356
|
-
const userData = {
|
|
357
|
-
id: sdkResult.data.user.id,
|
|
358
|
-
email: sdkResult.data.user.email,
|
|
359
|
-
name: sdkResult.data.user.name || void 0,
|
|
360
|
-
createdAt: sdkResult.data.user.createdAt,
|
|
361
|
-
updatedAt: sdkResult.data.user.updatedAt
|
|
362
|
-
};
|
|
363
|
-
const sessionData = {
|
|
364
|
-
userId: sdkResult.data.user.id,
|
|
365
|
-
token: sdkResult.data.accessToken,
|
|
366
|
-
expiresAt: "",
|
|
367
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
368
|
-
};
|
|
369
|
-
setUser(userData);
|
|
370
|
-
setSession(sessionData);
|
|
371
|
-
if (onAuthChange) {
|
|
372
|
-
onAuthChange(userData);
|
|
373
|
-
}
|
|
374
|
-
try {
|
|
375
|
-
await syncTokenToCookie(sdkResult.data.accessToken);
|
|
376
|
-
} catch (error) {
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
const errorMessage = sdkResult.error?.message || "Sign up failed";
|
|
380
|
-
throw new Error(errorMessage);
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
[insforge, onAuthChange]
|
|
384
|
-
);
|
|
385
|
-
const verifySignInCode = (0, import_react.useCallback)(
|
|
386
|
-
async (email, code) => {
|
|
387
|
-
if (code !== "123456") {
|
|
388
|
-
throw new Error("Invalid verification code");
|
|
389
|
-
}
|
|
390
|
-
throw new Error("Passwordless sign in via verification code is not yet implemented in the backend");
|
|
391
|
-
},
|
|
392
|
-
[insforge, onAuthChange]
|
|
393
|
-
);
|
|
394
317
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
395
318
|
InsforgeContext.Provider,
|
|
396
319
|
{
|
|
@@ -405,13 +328,10 @@ function InsforgeProvider({
|
|
|
405
328
|
signUp,
|
|
406
329
|
signOut,
|
|
407
330
|
updateUser,
|
|
408
|
-
//
|
|
409
|
-
sendVerificationCode,
|
|
410
|
-
verifySignUpCode,
|
|
411
|
-
verifySignInCode,
|
|
412
|
-
// Config
|
|
413
|
-
oauthProviders,
|
|
414
|
-
isConfigLoaded,
|
|
331
|
+
// Email verification (commented out - verification disabled for now)
|
|
332
|
+
// sendVerificationCode,
|
|
333
|
+
// verifySignUpCode,
|
|
334
|
+
// verifySignInCode,
|
|
415
335
|
// Base
|
|
416
336
|
baseUrl
|
|
417
337
|
},
|
|
@@ -446,13 +366,50 @@ function useSession() {
|
|
|
446
366
|
}
|
|
447
367
|
|
|
448
368
|
// src/hooks/useOAuthProviders.ts
|
|
369
|
+
var import_react2 = require("react");
|
|
449
370
|
function useOAuthProviders() {
|
|
450
|
-
const {
|
|
451
|
-
|
|
371
|
+
const { baseUrl } = useInsforge();
|
|
372
|
+
const [providers, setProviders] = (0, import_react2.useState)([]);
|
|
373
|
+
const [isLoaded, setIsLoaded] = (0, import_react2.useState)(false);
|
|
374
|
+
(0, import_react2.useEffect)(() => {
|
|
375
|
+
let mounted = true;
|
|
376
|
+
async function fetchProviders() {
|
|
377
|
+
try {
|
|
378
|
+
const response = await fetch(`${baseUrl}/api/auth/oauth/providers`);
|
|
379
|
+
if (!response.ok) {
|
|
380
|
+
if (mounted) {
|
|
381
|
+
setProviders([]);
|
|
382
|
+
setIsLoaded(true);
|
|
383
|
+
}
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const result = await response.json();
|
|
387
|
+
if (mounted) {
|
|
388
|
+
if (result?.data && Array.isArray(result.data)) {
|
|
389
|
+
setProviders(result.data);
|
|
390
|
+
} else {
|
|
391
|
+
setProviders([]);
|
|
392
|
+
}
|
|
393
|
+
setIsLoaded(true);
|
|
394
|
+
}
|
|
395
|
+
} catch (error) {
|
|
396
|
+
console.warn("[useOAuthProviders] Failed to fetch OAuth providers:", error);
|
|
397
|
+
if (mounted) {
|
|
398
|
+
setProviders([]);
|
|
399
|
+
setIsLoaded(true);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
fetchProviders();
|
|
404
|
+
return () => {
|
|
405
|
+
mounted = false;
|
|
406
|
+
};
|
|
407
|
+
}, [baseUrl]);
|
|
408
|
+
return { providers, isLoaded };
|
|
452
409
|
}
|
|
453
410
|
|
|
454
411
|
// src/components/SignIn.tsx
|
|
455
|
-
var
|
|
412
|
+
var import_react5 = require("react");
|
|
456
413
|
var import_sdk2 = require("@insforge/sdk");
|
|
457
414
|
|
|
458
415
|
// src/components/auth/AuthBranding.tsx
|
|
@@ -565,7 +522,7 @@ function AuthFormField({ label, id, className = "", ...props }) {
|
|
|
565
522
|
}
|
|
566
523
|
|
|
567
524
|
// src/components/auth/AuthPasswordField.tsx
|
|
568
|
-
var
|
|
525
|
+
var import_react3 = require("react");
|
|
569
526
|
var import_lucide_react3 = require("lucide-react");
|
|
570
527
|
|
|
571
528
|
// src/components/auth/AuthPasswordStrengthIndicator.tsx
|
|
@@ -621,8 +578,8 @@ function AuthPasswordField({
|
|
|
621
578
|
onFocus,
|
|
622
579
|
...props
|
|
623
580
|
}) {
|
|
624
|
-
const [showPassword, setShowPassword] = (0,
|
|
625
|
-
const [showStrength, setShowStrength] = (0,
|
|
581
|
+
const [showPassword, setShowPassword] = (0, import_react3.useState)(false);
|
|
582
|
+
const [showStrength, setShowStrength] = (0, import_react3.useState)(false);
|
|
626
583
|
const handleFocus = (e) => {
|
|
627
584
|
if (showStrengthIndicator) {
|
|
628
585
|
setShowStrength(true);
|
|
@@ -949,7 +906,7 @@ function AuthOAuthProviders({
|
|
|
949
906
|
}
|
|
950
907
|
|
|
951
908
|
// src/components/auth/AuthVerificationCodeInput.tsx
|
|
952
|
-
var
|
|
909
|
+
var import_react4 = require("react");
|
|
953
910
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
954
911
|
function AuthVerificationCodeInput({
|
|
955
912
|
length = 6,
|
|
@@ -958,7 +915,7 @@ function AuthVerificationCodeInput({
|
|
|
958
915
|
onChange,
|
|
959
916
|
disabled = false
|
|
960
917
|
}) {
|
|
961
|
-
const inputRefs = (0,
|
|
918
|
+
const inputRefs = (0, import_react4.useRef)([]);
|
|
962
919
|
const handleChange = (index, digit) => {
|
|
963
920
|
if (digit.length > 1) return;
|
|
964
921
|
if (digit && !/^\d$/.test(digit)) return;
|
|
@@ -1040,13 +997,14 @@ function SignIn({
|
|
|
1040
997
|
onSuccess,
|
|
1041
998
|
onError
|
|
1042
999
|
}) {
|
|
1043
|
-
const { signIn,
|
|
1044
|
-
const
|
|
1045
|
-
const [
|
|
1046
|
-
const [
|
|
1047
|
-
const [
|
|
1048
|
-
const [
|
|
1049
|
-
const
|
|
1000
|
+
const { signIn, baseUrl } = useInsforge();
|
|
1001
|
+
const { providers: oauthProviders } = useOAuthProviders();
|
|
1002
|
+
const [email, setEmail] = (0, import_react5.useState)("");
|
|
1003
|
+
const [password, setPassword] = (0, import_react5.useState)("");
|
|
1004
|
+
const [error, setError] = (0, import_react5.useState)("");
|
|
1005
|
+
const [loading, setLoading] = (0, import_react5.useState)(false);
|
|
1006
|
+
const [oauthLoading, setOauthLoading] = (0, import_react5.useState)(null);
|
|
1007
|
+
const insforge = (0, import_react5.useState)(() => (0, import_sdk2.createClient)({ baseUrl }))[0];
|
|
1050
1008
|
async function handleSubmit(e) {
|
|
1051
1009
|
e.preventDefault();
|
|
1052
1010
|
setLoading(true);
|
|
@@ -1109,11 +1067,7 @@ function SignIn({
|
|
|
1109
1067
|
value: password,
|
|
1110
1068
|
onChange: (e) => setPassword(e.target.value),
|
|
1111
1069
|
required: true,
|
|
1112
|
-
autoComplete: "current-password"
|
|
1113
|
-
forgotPasswordLink: {
|
|
1114
|
-
href: "#",
|
|
1115
|
-
text: forgotPasswordText
|
|
1116
|
-
}
|
|
1070
|
+
autoComplete: "current-password"
|
|
1117
1071
|
}
|
|
1118
1072
|
),
|
|
1119
1073
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
@@ -1143,7 +1097,7 @@ function SignIn({
|
|
|
1143
1097
|
}
|
|
1144
1098
|
|
|
1145
1099
|
// src/components/SignUp.tsx
|
|
1146
|
-
var
|
|
1100
|
+
var import_react6 = require("react");
|
|
1147
1101
|
var import_sdk3 = require("@insforge/sdk");
|
|
1148
1102
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1149
1103
|
function SignUp({
|
|
@@ -1157,9 +1111,9 @@ function SignUp({
|
|
|
1157
1111
|
passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
|
|
1158
1112
|
submitButtonText = "Sign Up",
|
|
1159
1113
|
loadingButtonText = "Creating account...",
|
|
1160
|
-
verifyButtonText = "Continue",
|
|
1161
|
-
loadingVerifyButtonText = "Verifying...",
|
|
1162
|
-
verifiedButtonText = "Verified",
|
|
1114
|
+
// verifyButtonText = "Continue", // Commented out - email verification disabled for now
|
|
1115
|
+
// loadingVerifyButtonText = "Verifying...", // Commented out - email verification disabled for now
|
|
1116
|
+
// verifiedButtonText = "Verified", // Commented out - email verification disabled for now
|
|
1163
1117
|
signInText = "Already have an account?",
|
|
1164
1118
|
signInLinkText = "Login Now",
|
|
1165
1119
|
signInUrl = "/sign-in",
|
|
@@ -1167,18 +1121,14 @@ function SignUp({
|
|
|
1167
1121
|
onSuccess,
|
|
1168
1122
|
onError
|
|
1169
1123
|
}) {
|
|
1170
|
-
const {
|
|
1171
|
-
const
|
|
1172
|
-
const [
|
|
1173
|
-
const [
|
|
1174
|
-
const [error, setError] = (0,
|
|
1175
|
-
const [loading, setLoading] = (0,
|
|
1176
|
-
const [oauthLoading, setOauthLoading] = (0,
|
|
1177
|
-
const
|
|
1178
|
-
const [step, setStep] = (0, import_react5.useState)(
|
|
1179
|
-
"credentials"
|
|
1180
|
-
);
|
|
1181
|
-
const insforge = (0, import_react5.useState)(() => (0, import_sdk3.createClient)({ baseUrl }))[0];
|
|
1124
|
+
const { signUp, baseUrl } = useInsforge();
|
|
1125
|
+
const { providers: oauthProviders } = useOAuthProviders();
|
|
1126
|
+
const [email, setEmail] = (0, import_react6.useState)("");
|
|
1127
|
+
const [password, setPassword] = (0, import_react6.useState)("");
|
|
1128
|
+
const [error, setError] = (0, import_react6.useState)("");
|
|
1129
|
+
const [loading, setLoading] = (0, import_react6.useState)(false);
|
|
1130
|
+
const [oauthLoading, setOauthLoading] = (0, import_react6.useState)(null);
|
|
1131
|
+
const insforge = (0, import_react6.useState)(() => (0, import_sdk3.createClient)({ baseUrl }))[0];
|
|
1182
1132
|
async function handleCredentialsSubmit(e) {
|
|
1183
1133
|
e.preventDefault();
|
|
1184
1134
|
setLoading(true);
|
|
@@ -1189,53 +1139,20 @@ function SignUp({
|
|
|
1189
1139
|
return;
|
|
1190
1140
|
}
|
|
1191
1141
|
try {
|
|
1192
|
-
await
|
|
1193
|
-
setStep("verification");
|
|
1194
|
-
} catch (err) {
|
|
1195
|
-
const errorMessage = err.message || "Failed to send verification code";
|
|
1196
|
-
setError(errorMessage);
|
|
1197
|
-
if (onError) onError(new Error(errorMessage));
|
|
1198
|
-
} finally {
|
|
1199
|
-
setLoading(false);
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
async function handleVerificationSubmit(e) {
|
|
1203
|
-
e.preventDefault();
|
|
1204
|
-
setLoading(true);
|
|
1205
|
-
setError("");
|
|
1206
|
-
if (verificationCode.length !== 6) {
|
|
1207
|
-
setError("Please enter the complete verification code");
|
|
1208
|
-
setLoading(false);
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
try {
|
|
1212
|
-
await verifySignUpCode(email, password, verificationCode);
|
|
1142
|
+
await signUp(email, password);
|
|
1213
1143
|
if (onSuccess) {
|
|
1214
|
-
setVerified(true);
|
|
1215
1144
|
const userResult = await insforge.auth.getCurrentUser();
|
|
1216
1145
|
if (userResult.data) onSuccess(userResult.data);
|
|
1217
1146
|
}
|
|
1218
1147
|
window.location.href = afterSignUpUrl;
|
|
1219
1148
|
} catch (err) {
|
|
1220
|
-
const errorMessage = err.message || "
|
|
1149
|
+
const errorMessage = err.message || "Sign up failed";
|
|
1221
1150
|
setError(errorMessage);
|
|
1222
1151
|
if (onError) onError(new Error(errorMessage));
|
|
1223
1152
|
} finally {
|
|
1224
1153
|
setLoading(false);
|
|
1225
1154
|
}
|
|
1226
1155
|
}
|
|
1227
|
-
async function handleResendCode() {
|
|
1228
|
-
setLoading(true);
|
|
1229
|
-
setError("");
|
|
1230
|
-
try {
|
|
1231
|
-
await sendVerificationCode(email, "signup");
|
|
1232
|
-
} catch (err) {
|
|
1233
|
-
const errorMessage = err.message || "Failed to resend code";
|
|
1234
|
-
setError(errorMessage);
|
|
1235
|
-
} finally {
|
|
1236
|
-
setLoading(false);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
1156
|
async function handleOAuth(provider) {
|
|
1240
1157
|
try {
|
|
1241
1158
|
setOauthLoading(provider);
|
|
@@ -1255,105 +1172,64 @@ function SignUp({
|
|
|
1255
1172
|
setOauthLoading(null);
|
|
1256
1173
|
}
|
|
1257
1174
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("form", { onSubmit: handleCredentialsSubmit, className: "insforge-form", children: [
|
|
1263
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1264
|
-
AuthFormField,
|
|
1265
|
-
{
|
|
1266
|
-
id: "email",
|
|
1267
|
-
type: "email",
|
|
1268
|
-
label: emailLabel,
|
|
1269
|
-
placeholder: emailPlaceholder,
|
|
1270
|
-
value: email,
|
|
1271
|
-
onChange: (e) => setEmail(e.target.value),
|
|
1272
|
-
required: true,
|
|
1273
|
-
autoComplete: "email"
|
|
1274
|
-
}
|
|
1275
|
-
),
|
|
1276
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1277
|
-
AuthPasswordField,
|
|
1278
|
-
{
|
|
1279
|
-
id: "password",
|
|
1280
|
-
label: passwordLabel,
|
|
1281
|
-
placeholder: passwordPlaceholder,
|
|
1282
|
-
value: password,
|
|
1283
|
-
onChange: (e) => setPassword(e.target.value),
|
|
1284
|
-
required: true,
|
|
1285
|
-
minLength: 8,
|
|
1286
|
-
autoComplete: "new-password",
|
|
1287
|
-
showStrengthIndicator: true
|
|
1288
|
-
}
|
|
1289
|
-
),
|
|
1290
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1291
|
-
AuthSubmitButton,
|
|
1292
|
-
{
|
|
1293
|
-
isLoading: loading,
|
|
1294
|
-
disabled: loading || oauthLoading !== null,
|
|
1295
|
-
style: appearance.button,
|
|
1296
|
-
children: loading ? loadingButtonText : submitButtonText
|
|
1297
|
-
}
|
|
1298
|
-
)
|
|
1299
|
-
] }),
|
|
1175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(AuthContainer, { style: appearance.container, children: [
|
|
1176
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AuthHeader, { title, subtitle }),
|
|
1177
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AuthErrorBanner, { error }),
|
|
1178
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("form", { onSubmit: handleCredentialsSubmit, className: "insforge-form", children: [
|
|
1300
1179
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1301
|
-
|
|
1180
|
+
AuthFormField,
|
|
1302
1181
|
{
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1182
|
+
id: "email",
|
|
1183
|
+
type: "email",
|
|
1184
|
+
label: emailLabel,
|
|
1185
|
+
placeholder: emailPlaceholder,
|
|
1186
|
+
value: email,
|
|
1187
|
+
onChange: (e) => setEmail(e.target.value),
|
|
1188
|
+
required: true,
|
|
1189
|
+
autoComplete: "email"
|
|
1306
1190
|
}
|
|
1307
1191
|
),
|
|
1308
|
-
oauthProviders.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
1309
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AuthDivider, { text: dividerText }),
|
|
1310
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1311
|
-
AuthOAuthProviders,
|
|
1312
|
-
{
|
|
1313
|
-
providers: oauthProviders,
|
|
1314
|
-
onClick: handleOAuth,
|
|
1315
|
-
disabled: loading || oauthLoading !== null,
|
|
1316
|
-
loading: oauthLoading
|
|
1317
|
-
}
|
|
1318
|
-
)
|
|
1319
|
-
] })
|
|
1320
|
-
] });
|
|
1321
|
-
}
|
|
1322
|
-
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(AuthContainer, { style: appearance.container, children: [
|
|
1323
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AuthHeader, { title, subtitle }),
|
|
1324
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AuthErrorBanner, { error }),
|
|
1325
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("form", { onSubmit: handleVerificationSubmit, className: "insforge-form", children: [
|
|
1326
1192
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1327
|
-
|
|
1193
|
+
AuthPasswordField,
|
|
1328
1194
|
{
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1195
|
+
id: "password",
|
|
1196
|
+
label: passwordLabel,
|
|
1197
|
+
placeholder: passwordPlaceholder,
|
|
1198
|
+
value: password,
|
|
1199
|
+
onChange: (e) => setPassword(e.target.value),
|
|
1200
|
+
required: true,
|
|
1201
|
+
minLength: 8,
|
|
1202
|
+
autoComplete: "new-password",
|
|
1203
|
+
showStrengthIndicator: true
|
|
1333
1204
|
}
|
|
1334
1205
|
),
|
|
1335
1206
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1336
1207
|
AuthSubmitButton,
|
|
1337
1208
|
{
|
|
1338
1209
|
isLoading: loading,
|
|
1339
|
-
disabled: loading,
|
|
1210
|
+
disabled: loading || oauthLoading !== null,
|
|
1340
1211
|
style: appearance.button,
|
|
1341
|
-
|
|
1342
|
-
children: verified ? verifiedButtonText : loading ? loadingVerifyButtonText : verifyButtonText
|
|
1212
|
+
children: loading ? loadingButtonText : submitButtonText
|
|
1343
1213
|
}
|
|
1344
1214
|
)
|
|
1345
1215
|
] }),
|
|
1346
|
-
/* @__PURE__ */ (0, import_jsx_runtime17.
|
|
1347
|
-
|
|
1348
|
-
|
|
1216
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1217
|
+
AuthLink,
|
|
1218
|
+
{
|
|
1219
|
+
text: signInText,
|
|
1220
|
+
linkText: signInLinkText,
|
|
1221
|
+
href: signInUrl
|
|
1222
|
+
}
|
|
1223
|
+
),
|
|
1224
|
+
oauthProviders.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
1225
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(AuthDivider, { text: dividerText }),
|
|
1349
1226
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1350
|
-
|
|
1227
|
+
AuthOAuthProviders,
|
|
1351
1228
|
{
|
|
1352
|
-
|
|
1353
|
-
onClick:
|
|
1354
|
-
disabled: loading,
|
|
1355
|
-
|
|
1356
|
-
children: "Click to resend"
|
|
1229
|
+
providers: oauthProviders,
|
|
1230
|
+
onClick: handleOAuth,
|
|
1231
|
+
disabled: loading || oauthLoading !== null,
|
|
1232
|
+
loading: oauthLoading
|
|
1357
1233
|
}
|
|
1358
1234
|
)
|
|
1359
1235
|
] })
|
|
@@ -1361,7 +1237,7 @@ function SignUp({
|
|
|
1361
1237
|
}
|
|
1362
1238
|
|
|
1363
1239
|
// src/components/UserButton.tsx
|
|
1364
|
-
var
|
|
1240
|
+
var import_react7 = require("react");
|
|
1365
1241
|
var import_lucide_react6 = require("lucide-react");
|
|
1366
1242
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1367
1243
|
function UserButton({
|
|
@@ -1370,9 +1246,9 @@ function UserButton({
|
|
|
1370
1246
|
appearance = {}
|
|
1371
1247
|
}) {
|
|
1372
1248
|
const { user, signOut } = useInsforge();
|
|
1373
|
-
const [isOpen, setIsOpen] = (0,
|
|
1374
|
-
const dropdownRef = (0,
|
|
1375
|
-
(0,
|
|
1249
|
+
const [isOpen, setIsOpen] = (0, import_react7.useState)(false);
|
|
1250
|
+
const dropdownRef = (0, import_react7.useRef)(null);
|
|
1251
|
+
(0, import_react7.useEffect)(() => {
|
|
1376
1252
|
function handleClickOutside(event) {
|
|
1377
1253
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
1378
1254
|
setIsOpen(false);
|
|
@@ -1437,7 +1313,7 @@ function SignedOut({ children }) {
|
|
|
1437
1313
|
}
|
|
1438
1314
|
|
|
1439
1315
|
// src/components/Protect.tsx
|
|
1440
|
-
var
|
|
1316
|
+
var import_react8 = require("react");
|
|
1441
1317
|
var import_navigation = require("next/navigation");
|
|
1442
1318
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
1443
1319
|
function Protect({
|
|
@@ -1448,7 +1324,7 @@ function Protect({
|
|
|
1448
1324
|
}) {
|
|
1449
1325
|
const { isSignedIn, isLoaded, user } = useInsforge();
|
|
1450
1326
|
const router = (0, import_navigation.useRouter)();
|
|
1451
|
-
(0,
|
|
1327
|
+
(0, import_react8.useEffect)(() => {
|
|
1452
1328
|
if (isLoaded && !isSignedIn) {
|
|
1453
1329
|
router.push(redirectTo);
|
|
1454
1330
|
} else if (isLoaded && isSignedIn && condition && user) {
|