react-unified-auth 1.0.1 → 1.0.2
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 +71 -8
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/package.json +10 -6
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var react = require('react');
|
|
5
5
|
|
|
6
|
-
const AuthContext =
|
|
6
|
+
const AuthContext = react.createContext(undefined);
|
|
7
7
|
function AuthProvider({ config, children }) {
|
|
8
8
|
return (jsxRuntime.jsx(AuthContext.Provider, { value: { config }, children: children }));
|
|
9
9
|
}
|
|
10
10
|
function useAuthConfig() {
|
|
11
|
-
const context =
|
|
11
|
+
const context = react.useContext(AuthContext);
|
|
12
12
|
if (!context) {
|
|
13
13
|
throw new Error('useAuthConfig must be used within an AuthProvider');
|
|
14
14
|
}
|
|
@@ -3957,9 +3957,9 @@ class ApiClient {
|
|
|
3957
3957
|
|
|
3958
3958
|
function useAuth() {
|
|
3959
3959
|
const config = useAuthConfig();
|
|
3960
|
-
const [user, setUser] =
|
|
3961
|
-
const [loading, setLoading] =
|
|
3962
|
-
const [error, setError] =
|
|
3960
|
+
const [user, setUser] = react.useState(null);
|
|
3961
|
+
const [loading, setLoading] = react.useState(false);
|
|
3962
|
+
const [error, setError] = react.useState(null);
|
|
3963
3963
|
const login = async (credentials) => {
|
|
3964
3964
|
setLoading(true);
|
|
3965
3965
|
setError(null);
|
|
@@ -4035,10 +4035,10 @@ function useAuth() {
|
|
|
4035
4035
|
|
|
4036
4036
|
function useDynamicForm(formId) {
|
|
4037
4037
|
const config = useAuthConfig();
|
|
4038
|
-
const [formConfig, setFormConfig] =
|
|
4039
|
-
const [loading, setLoading] =
|
|
4040
|
-
const [error, setError] =
|
|
4041
|
-
|
|
4038
|
+
const [formConfig, setFormConfig] = react.useState(null);
|
|
4039
|
+
const [loading, setLoading] = react.useState(false);
|
|
4040
|
+
const [error, setError] = react.useState(null);
|
|
4041
|
+
react.useEffect(() => {
|
|
4042
4042
|
const fetchFormConfig = async () => {
|
|
4043
4043
|
setLoading(true);
|
|
4044
4044
|
setError(null);
|
|
@@ -4124,9 +4124,9 @@ function validateForm(fields, values) {
|
|
|
4124
4124
|
}
|
|
4125
4125
|
|
|
4126
4126
|
function DynamicForm({ fields, onSubmit, submitText = 'Submit', submitVariant = 'primary', loading = false, }) {
|
|
4127
|
-
const [values, setValues] =
|
|
4128
|
-
const [errors, setErrors] =
|
|
4129
|
-
const [touched, setTouched] =
|
|
4127
|
+
const [values, setValues] = react.useState({});
|
|
4128
|
+
const [errors, setErrors] = react.useState({});
|
|
4129
|
+
const [touched, setTouched] = react.useState({});
|
|
4130
4130
|
const handleChange = (name, value) => {
|
|
4131
4131
|
setValues((prev) => ({ ...prev, [name]: value }));
|
|
4132
4132
|
if (touched[name]) {
|
|
@@ -4191,7 +4191,7 @@ function DynamicForm({ fields, onSubmit, submitText = 'Submit', submitVariant =
|
|
|
4191
4191
|
function LoginForm({ formId, onSuccess, onError }) {
|
|
4192
4192
|
const config = useAuthConfig();
|
|
4193
4193
|
const { formConfig, loading: formLoading, error: formError } = useDynamicForm(formId);
|
|
4194
|
-
const [submitting, setSubmitting] =
|
|
4194
|
+
const [submitting, setSubmitting] = react.useState(false);
|
|
4195
4195
|
const handleSubmit = async (values) => {
|
|
4196
4196
|
if (!formConfig)
|
|
4197
4197
|
return;
|