@djangocfg/api 2.1.37 → 2.1.39
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/README.md +94 -56
- package/dist/auth.cjs +12 -65
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +5 -7
- package/dist/auth.d.ts +5 -7
- package/dist/auth.mjs +12 -65
- package/dist/auth.mjs.map +1 -1
- package/package.json +3 -3
- package/src/auth/context/AuthContext.tsx +8 -71
- package/src/auth/context/types.ts +1 -9
- package/src/auth/hooks/useAuthForm.ts +11 -7
package/dist/auth.d.cts
CHANGED
|
@@ -260,7 +260,7 @@ interface AuthContextType {
|
|
|
260
260
|
success: boolean;
|
|
261
261
|
message: string;
|
|
262
262
|
}>;
|
|
263
|
-
verifyOTP: (identifier: string, otpCode: string, channel?: 'email' | 'phone', sourceUrl?: string) => Promise<{
|
|
263
|
+
verifyOTP: (identifier: string, otpCode: string, channel?: 'email' | 'phone', sourceUrl?: string, redirectUrl?: string) => Promise<{
|
|
264
264
|
success: boolean;
|
|
265
265
|
message: string;
|
|
266
266
|
user?: UserProfile;
|
|
@@ -270,12 +270,6 @@ interface AuthContextType {
|
|
|
270
270
|
message: string;
|
|
271
271
|
}>;
|
|
272
272
|
logout: () => Promise<void>;
|
|
273
|
-
getSavedRedirectUrl: () => string | null;
|
|
274
|
-
saveRedirectUrl: (url: string) => void;
|
|
275
|
-
clearSavedRedirectUrl: () => void;
|
|
276
|
-
getFinalRedirectUrl: () => string;
|
|
277
|
-
useAndClearRedirectUrl: () => string;
|
|
278
|
-
saveCurrentUrlForRedirect: () => void;
|
|
279
273
|
}
|
|
280
274
|
interface AuthProviderProps {
|
|
281
275
|
children: React$1.ReactNode;
|
|
@@ -372,6 +366,10 @@ interface UseAuthFormOptions {
|
|
|
372
366
|
onOTPSuccess?: () => void;
|
|
373
367
|
onError?: (message: string) => void;
|
|
374
368
|
sourceUrl: string;
|
|
369
|
+
/** URL to redirect after successful OTP verification */
|
|
370
|
+
redirectUrl?: string;
|
|
371
|
+
/** If true, user must accept terms before submitting. Default: false */
|
|
372
|
+
requireTermsAcceptance?: boolean;
|
|
375
373
|
}
|
|
376
374
|
declare const useAuthForm: (options: UseAuthFormOptions) => AuthFormState & AuthFormHandlers;
|
|
377
375
|
|
package/dist/auth.d.ts
CHANGED
|
@@ -260,7 +260,7 @@ interface AuthContextType {
|
|
|
260
260
|
success: boolean;
|
|
261
261
|
message: string;
|
|
262
262
|
}>;
|
|
263
|
-
verifyOTP: (identifier: string, otpCode: string, channel?: 'email' | 'phone', sourceUrl?: string) => Promise<{
|
|
263
|
+
verifyOTP: (identifier: string, otpCode: string, channel?: 'email' | 'phone', sourceUrl?: string, redirectUrl?: string) => Promise<{
|
|
264
264
|
success: boolean;
|
|
265
265
|
message: string;
|
|
266
266
|
user?: UserProfile;
|
|
@@ -270,12 +270,6 @@ interface AuthContextType {
|
|
|
270
270
|
message: string;
|
|
271
271
|
}>;
|
|
272
272
|
logout: () => Promise<void>;
|
|
273
|
-
getSavedRedirectUrl: () => string | null;
|
|
274
|
-
saveRedirectUrl: (url: string) => void;
|
|
275
|
-
clearSavedRedirectUrl: () => void;
|
|
276
|
-
getFinalRedirectUrl: () => string;
|
|
277
|
-
useAndClearRedirectUrl: () => string;
|
|
278
|
-
saveCurrentUrlForRedirect: () => void;
|
|
279
273
|
}
|
|
280
274
|
interface AuthProviderProps {
|
|
281
275
|
children: React$1.ReactNode;
|
|
@@ -372,6 +366,10 @@ interface UseAuthFormOptions {
|
|
|
372
366
|
onOTPSuccess?: () => void;
|
|
373
367
|
onError?: (message: string) => void;
|
|
374
368
|
sourceUrl: string;
|
|
369
|
+
/** URL to redirect after successful OTP verification */
|
|
370
|
+
redirectUrl?: string;
|
|
371
|
+
/** If true, user must accept terms before submitting. Default: false */
|
|
372
|
+
requireTermsAcceptance?: boolean;
|
|
375
373
|
}
|
|
376
374
|
declare const useAuthForm: (options: UseAuthFormOptions) => AuthFormState & AuthFormHandlers;
|
|
377
375
|
|
package/dist/auth.mjs
CHANGED
|
@@ -3906,7 +3906,6 @@ var defaultRoutes = {
|
|
|
3906
3906
|
var AuthContext = createContext2(void 0);
|
|
3907
3907
|
var EMAIL_STORAGE_KEY = "auth_email";
|
|
3908
3908
|
var PHONE_STORAGE_KEY = "auth_phone";
|
|
3909
|
-
var AUTH_REDIRECT_KEY = "auth_redirect_url";
|
|
3910
3909
|
var hasValidTokens = /* @__PURE__ */ __name(() => {
|
|
3911
3910
|
if (typeof window === "undefined") return false;
|
|
3912
3911
|
return api.isAuthenticated();
|
|
@@ -3926,7 +3925,6 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
3926
3925
|
const queryParams = useQueryParams();
|
|
3927
3926
|
const [storedEmail, setStoredEmail, clearStoredEmail] = useLocalStorage(EMAIL_STORAGE_KEY, null);
|
|
3928
3927
|
const [storedPhone, setStoredPhone, clearStoredPhone] = useLocalStorage(PHONE_STORAGE_KEY, null);
|
|
3929
|
-
const [redirectUrl, setRedirectUrl, clearRedirectUrl] = useLocalStorage(AUTH_REDIRECT_KEY, null);
|
|
3930
3928
|
const user = accounts.profile;
|
|
3931
3929
|
const userRef = useRef2(user);
|
|
3932
3930
|
const configRef = useRef2(config);
|
|
@@ -4108,7 +4106,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4108
4106
|
[accounts]
|
|
4109
4107
|
);
|
|
4110
4108
|
const verifyOTP = useCallback2(
|
|
4111
|
-
async (identifier, otpCode, channel, sourceUrl) => {
|
|
4109
|
+
async (identifier, otpCode, channel, sourceUrl, redirectUrl) => {
|
|
4112
4110
|
try {
|
|
4113
4111
|
const channelValue = channel === "phone" ? enums_exports.OTPVerifyRequestChannel.PHONE : enums_exports.OTPVerifyRequestChannel.EMAIL;
|
|
4114
4112
|
const result = await accounts.verifyOTP({
|
|
@@ -4138,13 +4136,8 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4138
4136
|
if (result.user?.id) {
|
|
4139
4137
|
Analytics.setUser(String(result.user.id));
|
|
4140
4138
|
}
|
|
4141
|
-
const
|
|
4142
|
-
|
|
4143
|
-
clearRedirectUrl();
|
|
4144
|
-
router.hardPush(redirectUrl);
|
|
4145
|
-
} else {
|
|
4146
|
-
router.hardPush(defaultCallback);
|
|
4147
|
-
}
|
|
4139
|
+
const finalRedirectUrl = redirectUrl || config?.routes?.defaultCallback || defaultRoutes.defaultCallback;
|
|
4140
|
+
router.hardPush(finalRedirectUrl);
|
|
4148
4141
|
return {
|
|
4149
4142
|
success: true,
|
|
4150
4143
|
message: "Login successful",
|
|
@@ -4162,7 +4155,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4162
4155
|
};
|
|
4163
4156
|
}
|
|
4164
4157
|
},
|
|
4165
|
-
[setStoredEmail, setStoredPhone, clearStoredEmail, clearStoredPhone,
|
|
4158
|
+
[setStoredEmail, setStoredPhone, clearStoredEmail, clearStoredPhone, config?.routes?.defaultCallback, accounts, router]
|
|
4166
4159
|
);
|
|
4167
4160
|
const refreshToken = useCallback2(async () => {
|
|
4168
4161
|
try {
|
|
@@ -4197,15 +4190,6 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4197
4190
|
};
|
|
4198
4191
|
}
|
|
4199
4192
|
}, [clearAuthState, accounts]);
|
|
4200
|
-
const clearRedirect = useCallback2(() => {
|
|
4201
|
-
clearRedirectUrl();
|
|
4202
|
-
}, [clearRedirectUrl]);
|
|
4203
|
-
const saveCurrentUrlForRedirect = useCallback2(() => {
|
|
4204
|
-
if (typeof window !== "undefined") {
|
|
4205
|
-
const currentUrl = window.location.pathname + window.location.search;
|
|
4206
|
-
setRedirectUrl(currentUrl);
|
|
4207
|
-
}
|
|
4208
|
-
}, [setRedirectUrl]);
|
|
4209
4193
|
const logout = useCallback2(async () => {
|
|
4210
4194
|
const performLogout = /* @__PURE__ */ __name(() => {
|
|
4211
4195
|
Analytics.event("auth_logout" /* AUTH_LOGOUT */, {
|
|
@@ -4235,31 +4219,6 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4235
4219
|
}
|
|
4236
4220
|
}
|
|
4237
4221
|
}, [accounts, config?.routes?.defaultAuthCallback, router]);
|
|
4238
|
-
const getSavedRedirectUrl = useCallback2(() => {
|
|
4239
|
-
if (typeof window !== "undefined") {
|
|
4240
|
-
return sessionStorage.getItem(AUTH_REDIRECT_KEY);
|
|
4241
|
-
}
|
|
4242
|
-
return null;
|
|
4243
|
-
}, []);
|
|
4244
|
-
const saveRedirectUrl = useCallback2((url) => {
|
|
4245
|
-
if (typeof window !== "undefined") {
|
|
4246
|
-
sessionStorage.setItem(AUTH_REDIRECT_KEY, url);
|
|
4247
|
-
}
|
|
4248
|
-
}, []);
|
|
4249
|
-
const clearSavedRedirectUrl = useCallback2(() => {
|
|
4250
|
-
if (typeof window !== "undefined") {
|
|
4251
|
-
sessionStorage.removeItem(AUTH_REDIRECT_KEY);
|
|
4252
|
-
}
|
|
4253
|
-
}, []);
|
|
4254
|
-
const getFinalRedirectUrl = useCallback2(() => {
|
|
4255
|
-
const savedUrl = getSavedRedirectUrl();
|
|
4256
|
-
return savedUrl || (config?.routes?.defaultCallback || defaultRoutes.defaultCallback);
|
|
4257
|
-
}, [getSavedRedirectUrl, config?.routes?.defaultCallback]);
|
|
4258
|
-
const useAndClearRedirectUrl = useCallback2(() => {
|
|
4259
|
-
const finalUrl = getFinalRedirectUrl();
|
|
4260
|
-
clearSavedRedirectUrl();
|
|
4261
|
-
return finalUrl;
|
|
4262
|
-
}, [getFinalRedirectUrl, clearSavedRedirectUrl]);
|
|
4263
4222
|
const isAdminUser = useMemo(() => {
|
|
4264
4223
|
return Boolean(user?.is_staff || user?.is_superuser);
|
|
4265
4224
|
}, [user]);
|
|
@@ -4283,13 +4242,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4283
4242
|
requestOTP,
|
|
4284
4243
|
verifyOTP,
|
|
4285
4244
|
refreshToken,
|
|
4286
|
-
logout
|
|
4287
|
-
getSavedRedirectUrl,
|
|
4288
|
-
saveRedirectUrl,
|
|
4289
|
-
clearSavedRedirectUrl,
|
|
4290
|
-
getFinalRedirectUrl,
|
|
4291
|
-
useAndClearRedirectUrl,
|
|
4292
|
-
saveCurrentUrlForRedirect
|
|
4245
|
+
logout
|
|
4293
4246
|
}),
|
|
4294
4247
|
[
|
|
4295
4248
|
user,
|
|
@@ -4306,13 +4259,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4306
4259
|
requestOTP,
|
|
4307
4260
|
verifyOTP,
|
|
4308
4261
|
refreshToken,
|
|
4309
|
-
logout
|
|
4310
|
-
getSavedRedirectUrl,
|
|
4311
|
-
saveRedirectUrl,
|
|
4312
|
-
clearSavedRedirectUrl,
|
|
4313
|
-
getFinalRedirectUrl,
|
|
4314
|
-
useAndClearRedirectUrl,
|
|
4315
|
-
saveCurrentUrlForRedirect
|
|
4262
|
+
logout
|
|
4316
4263
|
]
|
|
4317
4264
|
);
|
|
4318
4265
|
return /* @__PURE__ */ jsx2(AuthContext.Provider, { value, children });
|
|
@@ -4470,10 +4417,10 @@ function useSessionStorage(key, initialValue) {
|
|
|
4470
4417
|
__name(useSessionStorage, "useSessionStorage");
|
|
4471
4418
|
|
|
4472
4419
|
// src/auth/hooks/useAuthRedirect.ts
|
|
4473
|
-
var
|
|
4420
|
+
var AUTH_REDIRECT_KEY = "auth_redirect_url";
|
|
4474
4421
|
var useAuthRedirectManager = /* @__PURE__ */ __name((options = {}) => {
|
|
4475
4422
|
const { fallbackUrl = "/dashboard", clearOnUse = true } = options;
|
|
4476
|
-
const [redirectUrl, setRedirectUrl, removeRedirectUrl] = useSessionStorage(
|
|
4423
|
+
const [redirectUrl, setRedirectUrl, removeRedirectUrl] = useSessionStorage(AUTH_REDIRECT_KEY, "");
|
|
4477
4424
|
const setRedirect = /* @__PURE__ */ __name((url) => {
|
|
4478
4425
|
setRedirectUrl(url);
|
|
4479
4426
|
}, "setRedirect");
|
|
@@ -4717,7 +4664,7 @@ var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
4717
4664
|
|
|
4718
4665
|
// src/auth/hooks/useAuthForm.ts
|
|
4719
4666
|
var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
4720
|
-
const { onIdentifierSuccess, onOTPSuccess, onError, sourceUrl } = options;
|
|
4667
|
+
const { onIdentifierSuccess, onOTPSuccess, onError, sourceUrl, redirectUrl, requireTermsAcceptance = false } = options;
|
|
4721
4668
|
const [identifier, setIdentifier] = useState5("");
|
|
4722
4669
|
const [channel, setChannel] = useState5("email");
|
|
4723
4670
|
const [otp, setOtp] = useState5("");
|
|
@@ -4786,7 +4733,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
4786
4733
|
onError?.(message);
|
|
4787
4734
|
return;
|
|
4788
4735
|
}
|
|
4789
|
-
if (!acceptedTerms) {
|
|
4736
|
+
if (requireTermsAcceptance && !acceptedTerms) {
|
|
4790
4737
|
const message = "Please accept the Terms of Service and Privacy Policy";
|
|
4791
4738
|
setError(message);
|
|
4792
4739
|
onError?.(message);
|
|
@@ -4830,7 +4777,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
4830
4777
|
setIsLoading(true);
|
|
4831
4778
|
clearError();
|
|
4832
4779
|
try {
|
|
4833
|
-
const result = await verifyOTP(identifier, otp, channel, sourceUrl);
|
|
4780
|
+
const result = await verifyOTP(identifier, otp, channel, sourceUrl, redirectUrl);
|
|
4834
4781
|
if (result.success) {
|
|
4835
4782
|
if (channel === "email") {
|
|
4836
4783
|
setSavedEmail(identifier);
|
|
@@ -4851,7 +4798,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
4851
4798
|
} finally {
|
|
4852
4799
|
setIsLoading(false);
|
|
4853
4800
|
}
|
|
4854
|
-
}, [identifier, otp, channel, verifyOTP, clearError, setSavedEmail, onOTPSuccess, onError, sourceUrl]);
|
|
4801
|
+
}, [identifier, otp, channel, verifyOTP, clearError, setSavedEmail, onOTPSuccess, onError, sourceUrl, redirectUrl]);
|
|
4855
4802
|
const handleResendOTP = useCallback3(async () => {
|
|
4856
4803
|
setIsLoading(true);
|
|
4857
4804
|
clearError();
|