@neuroncloud/ido-react 0.1.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.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PropsWithChildren } from "react";
|
|
2
|
+
import { IdoClient, type BrowserClientOptions } from "@neuroncloud/ido-browser";
|
|
3
|
+
export interface IdoContextValue {
|
|
4
|
+
client: IdoClient;
|
|
5
|
+
isAuthenticated: boolean;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error?: Error;
|
|
8
|
+
}
|
|
9
|
+
export interface IdoProviderProps extends PropsWithChildren {
|
|
10
|
+
client?: IdoClient;
|
|
11
|
+
options?: BrowserClientOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare function IdoProvider({ children, client: suppliedClient, options, }: IdoProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<IdoContextValue | undefined>>;
|
|
14
|
+
export declare function useIdo(): IdoContextValue;
|
|
15
|
+
export declare function useIsAuthenticated(): boolean;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,SAAS,EACT,KAAK,oBAAoB,EAC1B,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,SAAS,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAID,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,MAAM,EAAE,cAAc,EACtB,OAAO,GACR,EAAE,gBAAgB,wGA6ClB;AAED,wBAAgB,MAAM,IAAI,eAAe,CAQxC;AAED,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createContext, createElement, useContext, useEffect, useMemo, useState, } from "react";
|
|
2
|
+
import { IdoClient, } from "@neuroncloud/ido-browser";
|
|
3
|
+
const IdoContext = createContext(undefined);
|
|
4
|
+
export function IdoProvider({ children, client: suppliedClient, options, }) {
|
|
5
|
+
const client = useMemo(() => {
|
|
6
|
+
if (suppliedClient) {
|
|
7
|
+
return suppliedClient;
|
|
8
|
+
}
|
|
9
|
+
if (!options) {
|
|
10
|
+
throw new Error("IdoProvider requires either client or options.");
|
|
11
|
+
}
|
|
12
|
+
return new IdoClient(options);
|
|
13
|
+
}, [options, suppliedClient]);
|
|
14
|
+
const [clientState, setClientState] = useState(() => client.clientStateManager.getClientState());
|
|
15
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
16
|
+
const [error, setError] = useState();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const unsubscribe = client.clientStateManager.subscribe(setClientState);
|
|
19
|
+
let active = true;
|
|
20
|
+
void client
|
|
21
|
+
.start()
|
|
22
|
+
.catch((cause) => {
|
|
23
|
+
if (active) {
|
|
24
|
+
setError(cause instanceof Error ? cause : new Error("IdentityOne client initialization failed."));
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.finally(() => {
|
|
28
|
+
if (active) {
|
|
29
|
+
setIsLoading(false);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return () => {
|
|
33
|
+
active = false;
|
|
34
|
+
unsubscribe();
|
|
35
|
+
void client.stop();
|
|
36
|
+
};
|
|
37
|
+
}, [client]);
|
|
38
|
+
return createElement(IdoContext.Provider, { value: { client, isAuthenticated: clientState.isAuthenticated, isLoading, error } }, children);
|
|
39
|
+
}
|
|
40
|
+
export function useIdo() {
|
|
41
|
+
const value = useContext(IdoContext);
|
|
42
|
+
if (!value) {
|
|
43
|
+
throw new Error("useIdo must be used inside IdoProvider.");
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
export function useIsAuthenticated() {
|
|
48
|
+
return useIdo().isAuthenticated;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,GAET,MAAM,OAAO,CAAC;AACf,OAAO,EACL,SAAS,GAEV,MAAM,0BAA0B,CAAC;AAclC,MAAM,UAAU,GAAG,aAAa,CAA8B,SAAS,CAAC,CAAC;AAEzE,MAAM,UAAU,WAAW,CAAC,EAC1B,QAAQ,EACR,MAAM,EAAE,cAAc,EACtB,OAAO,GACU;IACjB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;QAC1B,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;IAC9B,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,CAAC;IACjG,MAAM,CAAC,SAAS,EAAE,YAA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ED,MAAM,UAAU,kBAAkB;IAChC,OAAO,MAAM,EAAE,CAAC,eAAe,CAAC;AAClC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neuroncloud/ido-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@neuroncloud/ido-browser": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^19.1.10",
|
|
27
|
+
"react": "^19.1.1"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|