authera 1.1.0 → 1.1.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/dist/index.js +2 -5
- package/dist/web/login.d.ts +5 -0
- package/dist/web/login.js +35 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -3,20 +3,17 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { name2storage } from "./helper/storage";
|
|
4
4
|
import AuthProvider from "./web";
|
|
5
5
|
import { useAuth } from "./hooks/useAuth";
|
|
6
|
-
import
|
|
6
|
+
import LoginForm from "./web/login";
|
|
7
7
|
export default function AuthHook(props) {
|
|
8
8
|
// set storage functions
|
|
9
9
|
let storage = props.storage;
|
|
10
10
|
if (typeof storage === "string")
|
|
11
11
|
storage = name2storage(storage);
|
|
12
|
-
// fetch optoins from backend
|
|
13
|
-
const backend_url = props.backendUrl + "/options";
|
|
14
|
-
const response = axios.get(backend_url);
|
|
15
12
|
// create backend data
|
|
16
13
|
return {
|
|
17
14
|
createAuthProvider: (children) => (_jsx(AuthProvider, { storage: storage, fallback_401_url: props.fallback_401_url, children: children })),
|
|
18
15
|
useAuth: () => useAuth(),
|
|
19
|
-
LoginScenario: () => _jsx(
|
|
16
|
+
LoginScenario: () => _jsx(LoginForm, { baseURL: props.backendUrl }),
|
|
20
17
|
};
|
|
21
18
|
}
|
|
22
19
|
export { default as AuthGuard } from "./web/guard";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { convertFromSchema } from "minimal-form";
|
|
4
|
+
import EasyForm from "minimal-form";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { useForm } from "react-hook-form";
|
|
7
|
+
export default function LoginForm({ baseURL }) {
|
|
8
|
+
const [steps, stepsHnadler] = useState({});
|
|
9
|
+
const [activeStep, activeStepHandler] = useState("");
|
|
10
|
+
const [loading, loadingHandler] = useState(true);
|
|
11
|
+
const { handleSubmit, control } = useForm();
|
|
12
|
+
const request = axios.create({
|
|
13
|
+
baseURL,
|
|
14
|
+
});
|
|
15
|
+
// fetch data from steps
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
async function fetchSteps() {
|
|
18
|
+
const response = await request.get("/options");
|
|
19
|
+
const data = Object.entries(response.data).map(([opt, schema]) => [
|
|
20
|
+
opt,
|
|
21
|
+
convertFromSchema(schema),
|
|
22
|
+
]);
|
|
23
|
+
activeStepHandler(data[0][0]);
|
|
24
|
+
stepsHnadler(Object.fromEntries(data));
|
|
25
|
+
loadingHandler(false);
|
|
26
|
+
}
|
|
27
|
+
fetchSteps();
|
|
28
|
+
}, []);
|
|
29
|
+
const onSubmit = (data) => { };
|
|
30
|
+
// loading check
|
|
31
|
+
if (loading)
|
|
32
|
+
return _jsx("p", { children: "loading ..." });
|
|
33
|
+
// show forms from steps
|
|
34
|
+
return (_jsxs("form", { onSubmit: handleSubmit(onSubmit), children: [_jsx(EasyForm, { control: control, structure: steps[activeStep] }), _jsx("button", { type: "submit", children: "Submit" })] }));
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "authera",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "this project is a simple auth hook for react",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"axios": "^1.13.2",
|
|
42
|
-
"js-cookie": "^3.0.5"
|
|
42
|
+
"js-cookie": "^3.0.5",
|
|
43
|
+
"minimal-form": "^2.8.1",
|
|
44
|
+
"react-hook-form": "^7.66.0"
|
|
43
45
|
}
|
|
44
46
|
}
|