@ic-reactor/react 1.3.3 → 1.4.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/helpers/authHooks.js +8 -11
- package/package.json +8 -8
|
@@ -8,12 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.authHooks = void 0;
|
|
16
|
-
const
|
|
13
|
+
const React = require("react");
|
|
17
14
|
const zustand_1 = require("zustand");
|
|
18
15
|
const utils_1 = require("@ic-reactor/core/dist/utils");
|
|
19
16
|
const authHooks = (agentManager) => {
|
|
@@ -21,12 +18,12 @@ const authHooks = (agentManager) => {
|
|
|
21
18
|
const useAuthState = () => (0, zustand_1.useStore)(authStore);
|
|
22
19
|
const useUserPrincipal = () => { var _a, _b; return (_b = (_a = useAuthState()) === null || _a === void 0 ? void 0 : _a.identity) === null || _b === void 0 ? void 0 : _b.getPrincipal(); };
|
|
23
20
|
const useAuth = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
|
|
24
|
-
const [loginState, setLoginState] =
|
|
21
|
+
const [loginState, setLoginState] = React.useState({
|
|
25
22
|
loading: false,
|
|
26
23
|
error: undefined,
|
|
27
24
|
});
|
|
28
25
|
const { authenticated, authenticating, error, identity } = useAuthState();
|
|
29
|
-
const authenticate =
|
|
26
|
+
const authenticate = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
27
|
const authenticatePromise = new Promise((resolve, reject) => {
|
|
31
28
|
authenticator()
|
|
32
29
|
.then((identity) => {
|
|
@@ -46,7 +43,7 @@ const authHooks = (agentManager) => {
|
|
|
46
43
|
onAuthenticationSuccess,
|
|
47
44
|
onAuthenticationFailure,
|
|
48
45
|
]);
|
|
49
|
-
const login =
|
|
46
|
+
const login = React.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
47
|
setLoginState({ loading: true, error: undefined });
|
|
51
48
|
const loginPromise = new Promise((resolve, reject) => {
|
|
52
49
|
try {
|
|
@@ -56,12 +53,12 @@ const authHooks = (agentManager) => {
|
|
|
56
53
|
}
|
|
57
54
|
authClient.login(Object.assign(Object.assign({ identityProvider: getIsLocal()
|
|
58
55
|
? utils_1.LOCAL_INTERNET_IDENTITY_PROVIDER
|
|
59
|
-
: utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: () => {
|
|
56
|
+
: utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: (msg) => {
|
|
60
57
|
authenticate()
|
|
61
58
|
.then((identity) => {
|
|
62
59
|
var _a;
|
|
63
60
|
const principal = identity.getPrincipal();
|
|
64
|
-
(_a = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
61
|
+
(_a = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _a === void 0 ? void 0 : _a.call(options, msg);
|
|
65
62
|
onLoginSuccess === null || onLoginSuccess === void 0 ? void 0 : onLoginSuccess(principal);
|
|
66
63
|
resolve(principal);
|
|
67
64
|
setLoginState({ loading: false, error: undefined });
|
|
@@ -88,7 +85,7 @@ const authHooks = (agentManager) => {
|
|
|
88
85
|
});
|
|
89
86
|
onLogin === null || onLogin === void 0 ? void 0 : onLogin(() => loginPromise);
|
|
90
87
|
}), [onLogin, onLoginSuccess, onLoginError, authenticate]);
|
|
91
|
-
const logout =
|
|
88
|
+
const logout = React.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
89
|
const authClient = getAuth();
|
|
93
90
|
if (!authClient) {
|
|
94
91
|
throw new Error("Auth client not initialized");
|
|
@@ -97,7 +94,7 @@ const authHooks = (agentManager) => {
|
|
|
97
94
|
yield authenticate();
|
|
98
95
|
onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
|
|
99
96
|
}), [onLoggedOut]);
|
|
100
|
-
|
|
97
|
+
React.useEffect(() => {
|
|
101
98
|
const authClient = getAuth();
|
|
102
99
|
if (!authClient && !authenticating) {
|
|
103
100
|
authenticate();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A React library for interacting with Internet Computer canisters",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
"node": ">=10"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ic-reactor/core": "^1.
|
|
38
|
+
"@ic-reactor/core": "^1.4.0",
|
|
39
39
|
"zustand-utils": "^1.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@dfinity/agent": "
|
|
43
|
-
"@dfinity/auth-client": "
|
|
44
|
-
"@dfinity/candid": "
|
|
45
|
-
"@dfinity/identity": "
|
|
46
|
-
"@dfinity/principal": "
|
|
42
|
+
"@dfinity/agent": "^1.2",
|
|
43
|
+
"@dfinity/auth-client": "^1.2",
|
|
44
|
+
"@dfinity/candid": "^1.2",
|
|
45
|
+
"@dfinity/identity": "^1.2",
|
|
46
|
+
"@dfinity/principal": "^1.2",
|
|
47
47
|
"react": ">=16.8",
|
|
48
48
|
"zustand": "4.5"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "a302e73db60f96faf9f0119ecdd02ee8dfcaa1df"
|
|
51
51
|
}
|