@sylphx/sdk 0.10.5 → 0.10.6
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.ts +10 -8
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.d.ts +18 -0
- package/dist/nextjs/index.mjs +185 -1
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.mjs +34 -17
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/health/index.d.ts +0 -681
package/dist/react/index.d.ts
CHANGED
|
@@ -2318,6 +2318,8 @@ interface ResendVerificationEmailOptions {
|
|
|
2318
2318
|
interface ForgotPasswordOptions {
|
|
2319
2319
|
/** Email address to send reset link to */
|
|
2320
2320
|
email: string;
|
|
2321
|
+
/** Absolute reset URL. Next.js apps should normally use the SDK middleware route. */
|
|
2322
|
+
redirectUrl?: string;
|
|
2321
2323
|
}
|
|
2322
2324
|
/**
|
|
2323
2325
|
* Options for magic link (passwordless) sign-in.
|
|
@@ -4156,7 +4158,9 @@ interface SdkAuthContextValue {
|
|
|
4156
4158
|
invitationToken?: string;
|
|
4157
4159
|
metadata?: Record<string, unknown>;
|
|
4158
4160
|
}) => Promise<SdkRegisterResult>;
|
|
4159
|
-
forgotPassword: (email: string
|
|
4161
|
+
forgotPassword: (email: string, options?: {
|
|
4162
|
+
redirectUrl?: string;
|
|
4163
|
+
}) => Promise<{
|
|
4160
4164
|
success: boolean;
|
|
4161
4165
|
message: string;
|
|
4162
4166
|
}>;
|
package/dist/react/index.mjs
CHANGED
|
@@ -10817,6 +10817,13 @@ function useFlagOverrides() {
|
|
|
10817
10817
|
|
|
10818
10818
|
// src/react/hooks/use-forgot-password-form.ts
|
|
10819
10819
|
import { useCallback as useCallback22, useContext as useContext13, useState as useState26 } from "react";
|
|
10820
|
+
function resolveRedirectUrl(redirectTo) {
|
|
10821
|
+
if (/^https?:\/\//iu.test(redirectTo)) return redirectTo;
|
|
10822
|
+
if (typeof window !== "undefined" && redirectTo.startsWith("/")) {
|
|
10823
|
+
return new URL(redirectTo, window.location.origin).toString();
|
|
10824
|
+
}
|
|
10825
|
+
return redirectTo;
|
|
10826
|
+
}
|
|
10820
10827
|
function useForgotPasswordForm(options = {}) {
|
|
10821
10828
|
const { redirectTo = "/reset-password", submitHandler, onSuccess, onError } = options;
|
|
10822
10829
|
const authContext = useContext13(SdkAuthContext);
|
|
@@ -10849,7 +10856,9 @@ function useForgotPasswordForm(options = {}) {
|
|
|
10849
10856
|
setError("SDK not configured. Please wrap your app with SylphxProvider.");
|
|
10850
10857
|
return;
|
|
10851
10858
|
}
|
|
10852
|
-
await authContext.forgotPassword(form.email
|
|
10859
|
+
await authContext.forgotPassword(form.email, {
|
|
10860
|
+
redirectUrl: resolveRedirectUrl(redirectTo)
|
|
10861
|
+
});
|
|
10853
10862
|
}
|
|
10854
10863
|
setSuccess(true);
|
|
10855
10864
|
onSuccess?.();
|
|
@@ -13105,7 +13114,7 @@ function SylphxProviderInner({
|
|
|
13105
13114
|
window.history.replaceState({}, "", cleanUrl.toString());
|
|
13106
13115
|
}
|
|
13107
13116
|
}, []);
|
|
13108
|
-
const
|
|
13117
|
+
const resolveRedirectUrl2 = useCallback27((url) => {
|
|
13109
13118
|
if (typeof window === "undefined") return "";
|
|
13110
13119
|
if (!url) return window.location.href;
|
|
13111
13120
|
if (url.startsWith("/") && !url.startsWith("//")) {
|
|
@@ -13115,7 +13124,7 @@ function SylphxProviderInner({
|
|
|
13115
13124
|
}, []);
|
|
13116
13125
|
const signIn = useCallback27(
|
|
13117
13126
|
(options) => {
|
|
13118
|
-
const resolvedUrl =
|
|
13127
|
+
const resolvedUrl = resolveRedirectUrl2(options?.redirectUrl);
|
|
13119
13128
|
const redirectUri = isValidRedirectUrl(resolvedUrl, {
|
|
13120
13129
|
allowedOrigins: [platformUrl]
|
|
13121
13130
|
}) ? resolvedUrl : typeof window !== "undefined" ? window.location.href : "";
|
|
@@ -13131,11 +13140,11 @@ function SylphxProviderInner({
|
|
|
13131
13140
|
window.location.href = `${platformUrl}/auth/authorize?${params}`;
|
|
13132
13141
|
}
|
|
13133
13142
|
},
|
|
13134
|
-
[appId, platformUrl,
|
|
13143
|
+
[appId, platformUrl, resolveRedirectUrl2]
|
|
13135
13144
|
);
|
|
13136
13145
|
const signUp = useCallback27(
|
|
13137
13146
|
(options) => {
|
|
13138
|
-
const resolvedUrl =
|
|
13147
|
+
const resolvedUrl = resolveRedirectUrl2(options?.redirectUrl);
|
|
13139
13148
|
const redirectUri = isValidRedirectUrl(resolvedUrl, {
|
|
13140
13149
|
allowedOrigins: [platformUrl]
|
|
13141
13150
|
}) ? resolvedUrl : typeof window !== "undefined" ? window.location.href : "";
|
|
@@ -13152,7 +13161,7 @@ function SylphxProviderInner({
|
|
|
13152
13161
|
window.location.href = `${platformUrl}/auth/authorize?${params}`;
|
|
13153
13162
|
}
|
|
13154
13163
|
},
|
|
13155
|
-
[appId, platformUrl,
|
|
13164
|
+
[appId, platformUrl, resolveRedirectUrl2]
|
|
13156
13165
|
);
|
|
13157
13166
|
const signOut = useCallback27(
|
|
13158
13167
|
async (options) => {
|
|
@@ -13226,7 +13235,7 @@ function SylphxProviderInner({
|
|
|
13226
13235
|
async (options) => {
|
|
13227
13236
|
await api.post("/auth/reset-password", {
|
|
13228
13237
|
token: options.token,
|
|
13229
|
-
|
|
13238
|
+
password: options.newPassword
|
|
13230
13239
|
});
|
|
13231
13240
|
},
|
|
13232
13241
|
[api]
|
|
@@ -13245,9 +13254,13 @@ function SylphxProviderInner({
|
|
|
13245
13254
|
);
|
|
13246
13255
|
const forgotPassword = useCallback27(
|
|
13247
13256
|
async (options) => {
|
|
13248
|
-
|
|
13257
|
+
const redirectUrl = resolveRedirectUrl2(options.redirectUrl ?? "/reset-password");
|
|
13258
|
+
await api.post("/auth/forgot-password", {
|
|
13259
|
+
email: options.email,
|
|
13260
|
+
...redirectUrl ? { redirectUrl } : {}
|
|
13261
|
+
});
|
|
13249
13262
|
},
|
|
13250
|
-
[api]
|
|
13263
|
+
[api, resolveRedirectUrl2]
|
|
13251
13264
|
);
|
|
13252
13265
|
const clearOAuthError = useCallback27(() => {
|
|
13253
13266
|
setAuthState((prev) => ({ ...prev, oauthError: null }));
|
|
@@ -13255,7 +13268,7 @@ function SylphxProviderInner({
|
|
|
13255
13268
|
const signInWithOAuth = useCallback27(
|
|
13256
13269
|
async (options) => {
|
|
13257
13270
|
const { provider, redirectUrl, scopes } = options;
|
|
13258
|
-
const finalDestination =
|
|
13271
|
+
const finalDestination = resolveRedirectUrl2(redirectUrl);
|
|
13259
13272
|
setAuthState((prev) => ({
|
|
13260
13273
|
...prev,
|
|
13261
13274
|
isOAuthLoading: true,
|
|
@@ -13303,7 +13316,7 @@ function SylphxProviderInner({
|
|
|
13303
13316
|
throw error;
|
|
13304
13317
|
}
|
|
13305
13318
|
},
|
|
13306
|
-
[platformUrl, appId,
|
|
13319
|
+
[platformUrl, appId, resolveRedirectUrl2, authPrefix]
|
|
13307
13320
|
);
|
|
13308
13321
|
const signInWithGoogle = useCallback27(
|
|
13309
13322
|
(redirectUrl) => signInWithOAuth({ provider: "google", redirectUrl }),
|
|
@@ -13332,7 +13345,7 @@ function SylphxProviderInner({
|
|
|
13332
13345
|
const signInWithMagicLink = useCallback27(
|
|
13333
13346
|
async (options) => {
|
|
13334
13347
|
const { email, redirectUrl } = options;
|
|
13335
|
-
const resolvedRedirect =
|
|
13348
|
+
const resolvedRedirect = resolveRedirectUrl2(redirectUrl);
|
|
13336
13349
|
const response = await fetch(`${platformUrl}${SDK_API_PATH}/auth/magic-link`, {
|
|
13337
13350
|
method: "POST",
|
|
13338
13351
|
headers: {
|
|
@@ -13349,7 +13362,7 @@ function SylphxProviderInner({
|
|
|
13349
13362
|
throw new Error(error.message || "Failed to send magic link");
|
|
13350
13363
|
}
|
|
13351
13364
|
},
|
|
13352
|
-
[platformUrl, appId,
|
|
13365
|
+
[platformUrl, appId, resolveRedirectUrl2]
|
|
13353
13366
|
);
|
|
13354
13367
|
const createCheckout = useCallback27(
|
|
13355
13368
|
async (planSlug, interval) => {
|
|
@@ -14106,8 +14119,12 @@ function SylphxProviderInner({
|
|
|
14106
14119
|
}
|
|
14107
14120
|
};
|
|
14108
14121
|
},
|
|
14109
|
-
forgotPassword: async (email) => {
|
|
14110
|
-
const
|
|
14122
|
+
forgotPassword: async (email, options) => {
|
|
14123
|
+
const redirectUrl = resolveRedirectUrl2(options?.redirectUrl ?? "/reset-password");
|
|
14124
|
+
const result = await api.post("/auth/forgot-password", {
|
|
14125
|
+
email,
|
|
14126
|
+
...redirectUrl ? { redirectUrl } : {}
|
|
14127
|
+
});
|
|
14111
14128
|
return {
|
|
14112
14129
|
success: result.success,
|
|
14113
14130
|
message: "Password reset email sent"
|
|
@@ -14116,7 +14133,7 @@ function SylphxProviderInner({
|
|
|
14116
14133
|
resetPassword: async (token, password) => {
|
|
14117
14134
|
return await api.post("/auth/reset-password", {
|
|
14118
14135
|
token,
|
|
14119
|
-
|
|
14136
|
+
password
|
|
14120
14137
|
});
|
|
14121
14138
|
},
|
|
14122
14139
|
verifyEmail: async (token) => {
|
|
@@ -14152,7 +14169,7 @@ function SylphxProviderInner({
|
|
|
14152
14169
|
return { providers: data.providers || [] };
|
|
14153
14170
|
}
|
|
14154
14171
|
}),
|
|
14155
|
-
[api, platformUrl, appId, saveTokens, clearTokens]
|
|
14172
|
+
[api, platformUrl, appId, saveTokens, clearTokens, resolveRedirectUrl2]
|
|
14156
14173
|
);
|
|
14157
14174
|
const userValue = useMemo9(
|
|
14158
14175
|
() => ({
|