@nauth-toolkit/client 0.7.4 → 0.8.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/dist/index.cjs +52 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.mjs +52 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -94,6 +94,7 @@ var NAuthErrorCode = /* @__PURE__ */ ((NAuthErrorCode2) => {
|
|
|
94
94
|
NAuthErrorCode2["SOCIAL_CONFIG_MISSING"] = "SOCIAL_CONFIG_MISSING";
|
|
95
95
|
NAuthErrorCode2["SOCIAL_EMAIL_REQUIRED"] = "SOCIAL_EMAIL_REQUIRED";
|
|
96
96
|
NAuthErrorCode2["SOCIAL_ACCOUNT_NOT_FOUND"] = "SOCIAL_ACCOUNT_NOT_FOUND";
|
|
97
|
+
NAuthErrorCode2["SOCIAL_ACCESS_DENIED"] = "SOCIAL_ACCESS_DENIED";
|
|
97
98
|
NAuthErrorCode2["CHALLENGE_EXPIRED"] = "CHALLENGE_EXPIRED";
|
|
98
99
|
NAuthErrorCode2["CHALLENGE_INVALID"] = "CHALLENGE_INVALID";
|
|
99
100
|
NAuthErrorCode2["CHALLENGE_TYPE_MISMATCH"] = "CHALLENGE_TYPE_MISMATCH";
|
|
@@ -250,6 +251,7 @@ var resolveConfig = (config, defaultAdapter) => {
|
|
|
250
251
|
cookieName: config.csrf?.cookieName ?? "nauth_csrf_token",
|
|
251
252
|
headerName: config.csrf?.headerName ?? "x-csrf-token"
|
|
252
253
|
},
|
|
254
|
+
autoDetectLocale: config.autoDetectLocale ?? true,
|
|
253
255
|
deviceTrust: {
|
|
254
256
|
headerName: config.deviceTrust?.headerName ?? "X-Device-Token",
|
|
255
257
|
storageKey: config.deviceTrust?.storageKey ?? "nauth_device_token"
|
|
@@ -2145,6 +2147,42 @@ var OIDCOperations = class {
|
|
|
2145
2147
|
}
|
|
2146
2148
|
};
|
|
2147
2149
|
|
|
2150
|
+
// src/core/environment.ts
|
|
2151
|
+
function hasBrowserEnvironment() {
|
|
2152
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
2153
|
+
}
|
|
2154
|
+
function detectTimezone() {
|
|
2155
|
+
if (!hasBrowserEnvironment()) return void 0;
|
|
2156
|
+
try {
|
|
2157
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
|
|
2158
|
+
} catch {
|
|
2159
|
+
return void 0;
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
function detectLocale() {
|
|
2163
|
+
if (!hasBrowserEnvironment()) return void 0;
|
|
2164
|
+
try {
|
|
2165
|
+
const preferred = typeof navigator !== "undefined" ? navigator.language : void 0;
|
|
2166
|
+
if (preferred) return preferred;
|
|
2167
|
+
return Intl.DateTimeFormat().resolvedOptions().locale || void 0;
|
|
2168
|
+
} catch {
|
|
2169
|
+
return void 0;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
function withDetectedPreferences(supplied, enabled) {
|
|
2173
|
+
if (!enabled) return supplied;
|
|
2174
|
+
const result = { ...supplied };
|
|
2175
|
+
if (!("timezone" in supplied)) {
|
|
2176
|
+
const timezone = detectTimezone();
|
|
2177
|
+
if (timezone) result.timezone = timezone;
|
|
2178
|
+
}
|
|
2179
|
+
if (!("locale" in supplied)) {
|
|
2180
|
+
const locale = detectLocale();
|
|
2181
|
+
if (locale) result.locale = locale;
|
|
2182
|
+
}
|
|
2183
|
+
return result;
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2148
2186
|
// src/core/client.ts
|
|
2149
2187
|
var USER_KEY2 = "nauth_user";
|
|
2150
2188
|
var CHALLENGE_KEY2 = "nauth_challenge_session";
|
|
@@ -2323,6 +2361,7 @@ var NAuthClient = class {
|
|
|
2323
2361
|
* Signup with credentials.
|
|
2324
2362
|
*/
|
|
2325
2363
|
async signup(payload) {
|
|
2364
|
+
payload = withDetectedPreferences(payload, this.config.autoDetectLocale);
|
|
2326
2365
|
this.eventEmitter.emit({ type: "auth:signup", data: { email: payload.email }, timestamp: Date.now() });
|
|
2327
2366
|
try {
|
|
2328
2367
|
const response = await this.post(this.config.endpoints.signup, payload);
|
|
@@ -2669,14 +2708,16 @@ var NAuthClient = class {
|
|
|
2669
2708
|
return result;
|
|
2670
2709
|
}
|
|
2671
2710
|
/**
|
|
2672
|
-
*
|
|
2711
|
+
* Complete an admin-initiated password reset with a verification code.
|
|
2673
2712
|
*
|
|
2674
2713
|
* NOTE:
|
|
2675
|
-
* -
|
|
2676
|
-
*
|
|
2714
|
+
* - Admin-initiated only. A self-service "forgot password" code (from {@link forgotPassword}) is NOT
|
|
2715
|
+
* accepted here — use {@link confirmForgotPassword} for that flow instead. The two codes are validated
|
|
2716
|
+
* against different token types server-side and are not interchangeable, even though the emailed link
|
|
2717
|
+
* format is identical between the two flows (`...?code=123456`, no distinguishing marker).
|
|
2677
2718
|
*
|
|
2678
|
-
* WHY:
|
|
2679
|
-
*
|
|
2719
|
+
* WHY: Posts to the admin-reset confirm endpoint (`confirmAdminResetPassword`), which only recognizes
|
|
2720
|
+
* codes generated by an admin's `adminResetPassword` call.
|
|
2680
2721
|
*
|
|
2681
2722
|
* @param identifier - User identifier (email, username, phone)
|
|
2682
2723
|
* @param code - Verification code from email/SMS (6-10 digits)
|
|
@@ -3037,6 +3078,12 @@ var NAuthClient = class {
|
|
|
3037
3078
|
if (typeof options?.appState === "string" && options.appState.trim() !== "") {
|
|
3038
3079
|
startUrl.searchParams.set("appState", options.appState);
|
|
3039
3080
|
}
|
|
3081
|
+
if (this.config.autoDetectLocale) {
|
|
3082
|
+
const timezone = detectTimezone();
|
|
3083
|
+
const locale = detectLocale();
|
|
3084
|
+
if (timezone) startUrl.searchParams.set("timezone", timezone);
|
|
3085
|
+
if (locale) startUrl.searchParams.set("locale", locale);
|
|
3086
|
+
}
|
|
3040
3087
|
if (options?.oauthParams && Object.keys(options.oauthParams).length > 0) {
|
|
3041
3088
|
startUrl.searchParams.set("oauthParams", JSON.stringify(options.oauthParams));
|
|
3042
3089
|
}
|