@descope/react-sdk 0.0.51 → 0.0.52-alpha.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/README.md +18 -3
- package/dist/index.d.ts +64 -0
- package/dist/index.js +1 -0
- package/package.json +8 -5
- package/dist/Descope.d.ts +0 -12
- package/dist/Descope.js +0 -28
- package/dist/types.d.ts +0 -17
package/README.md
CHANGED
|
@@ -9,14 +9,29 @@ npm install @descope/react-sdk
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
### Render it in your application
|
|
12
|
+
#### Wrap your app with Auth Provider
|
|
12
13
|
```js
|
|
13
|
-
import
|
|
14
|
+
import { AuthProvider } from '@descope/react-sdk'
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
+
const AppRoot = () => {
|
|
17
|
+
return (
|
|
18
|
+
<AuthProvider
|
|
19
|
+
projectId="myProjectId"
|
|
20
|
+
>
|
|
21
|
+
<App />
|
|
22
|
+
</AuthProvider>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
#### Use Descope to render specific flow
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { Descope } from '@descope/react-sdk'
|
|
16
30
|
|
|
31
|
+
const App = () => {
|
|
17
32
|
return (
|
|
33
|
+
{...}
|
|
18
34
|
<Descope
|
|
19
|
-
projectId="myProjectId"
|
|
20
35
|
flowId="myFlowId"
|
|
21
36
|
onSuccess={(e) => console.log('Logged in!')}
|
|
22
37
|
onError={(e) => console.log('Could not logged in!')}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { DOMAttributes, FC } from 'react';
|
|
2
|
+
import DescopeWc from '@descope/web-component';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
['descope-wc']: DescopeCustomElement;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare type CustomEvents<K extends string> = {
|
|
12
|
+
[key in K]: (event: CustomEvent) => void;
|
|
13
|
+
};
|
|
14
|
+
declare type CustomElement<T, K extends string = ''> = Partial<T & DOMAttributes<T> & {
|
|
15
|
+
children: React.ReactChild;
|
|
16
|
+
ref: React.Ref<HTMLElement>;
|
|
17
|
+
} & CustomEvents<`on${K}`>>;
|
|
18
|
+
declare type DescopeCustomElement = CustomElement<DescopeWc, 'success' | 'error'>;
|
|
19
|
+
declare enum UserStatus {
|
|
20
|
+
enabled = "enabled",
|
|
21
|
+
disabled = "disabled",
|
|
22
|
+
invited = "invited",
|
|
23
|
+
unknown = "unknown"
|
|
24
|
+
}
|
|
25
|
+
interface IExternalID {
|
|
26
|
+
id: string;
|
|
27
|
+
type?: string;
|
|
28
|
+
}
|
|
29
|
+
interface User {
|
|
30
|
+
externalIDs?: IExternalID[];
|
|
31
|
+
displayName?: string;
|
|
32
|
+
project?: string;
|
|
33
|
+
logoutTime?: number;
|
|
34
|
+
createTime?: number;
|
|
35
|
+
email?: string;
|
|
36
|
+
phoneNumber?: string;
|
|
37
|
+
status?: UserStatus;
|
|
38
|
+
verifiedEmail?: boolean;
|
|
39
|
+
verifiedPhone?: boolean;
|
|
40
|
+
tenants?: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare const useAuth: () => {
|
|
44
|
+
projectId: string;
|
|
45
|
+
baseUrl: string;
|
|
46
|
+
authenticated: boolean;
|
|
47
|
+
user: User;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
interface PropsType {
|
|
51
|
+
flowId: string;
|
|
52
|
+
onSuccess?: DescopeCustomElement['onsuccess'];
|
|
53
|
+
onError?: DescopeCustomElement['onerror'];
|
|
54
|
+
}
|
|
55
|
+
declare const Descope: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<HTMLElement>>;
|
|
56
|
+
|
|
57
|
+
interface IAuthProviderProps {
|
|
58
|
+
projectId: string;
|
|
59
|
+
baseUrl?: string;
|
|
60
|
+
children?: JSX.Element;
|
|
61
|
+
}
|
|
62
|
+
declare const AuthProvider: FC<IAuthProviderProps>;
|
|
63
|
+
|
|
64
|
+
export { AuthProvider, Descope, useAuth };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e,{useMemo as r,useRef as t,useImperativeHandle as o,useCallback as s,useEffect as n,useState as c}from"react";import"@descope/web-component";const d=e.createContext(void 0),u=()=>{const t=e.useContext(d);if(!t)throw Error("You can only use useAuth in the context of <AuthProvider />");const{authenticated:o,user:s,projectId:n,baseUrl:c}=t;return r((()=>({projectId:n,baseUrl:c,authenticated:o,user:s})),[n,c,o,s])},a=e.forwardRef((({flowId:r,onSuccess:c,onError:u},a)=>{const i=t();o(a,(()=>i.current));const{projectId:l,baseUrl:p,setAuthenticated:v,setUser:h}=e.useContext(d),f=s((e=>{h(e?.detail?.user),v(!0),c&&c(e)}),[h,v,c]);return n((()=>{const e=i.current;return e?.addEventListener("success",f),u&&e?.addEventListener("error",u),()=>{u&&e?.removeEventListener("error",u),e?.removeEventListener("success",f)}}),[i,u,f]),e.createElement("descope-wc",{"project-id":l,"flow-id":r,"base-url":p,ref:i})}));a.defaultProps={onError:void 0,onSuccess:void 0};const i=({projectId:t,baseUrl:o,children:s})=>{const[n,u]=c(!1),[a,i]=c({}),l=r((()=>({user:a,authenticated:n,projectId:t,baseUrl:o,setUser:i,setAuthenticated:u})),[n,a,t,o]);return e.createElement(d.Provider,{value:l},s)};i.defaultProps={baseUrl:"",children:void 0};export{i as AuthProvider,a as Descope,u as useAuth};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/react-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"types": "dist/
|
|
3
|
+
"version": "0.0.52-alpha.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "Descope React SDK",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@descope/web-component": "^0.0.
|
|
16
|
+
"@descope/web-component": "^0.0.26-alpha.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@babel/core": "7.18.9",
|
|
@@ -55,10 +55,13 @@
|
|
|
55
55
|
"react": "18.2.0",
|
|
56
56
|
"react-dom": "18.2.0",
|
|
57
57
|
"rollup": "^2.62.0",
|
|
58
|
+
"rollup-plugin-auto-external": "^2.0.0",
|
|
58
59
|
"rollup-plugin-browsersync": "^1.3.3",
|
|
59
60
|
"rollup-plugin-delete": "^2.0.0",
|
|
61
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
60
62
|
"rollup-plugin-livereload": "^2.0.5",
|
|
61
63
|
"rollup-plugin-serve": "^1.1.0",
|
|
64
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
62
65
|
"ts-jest": "^27.0.7",
|
|
63
66
|
"ts-node": "10.9.1",
|
|
64
67
|
"typescript": "^4.5.3"
|
|
@@ -68,7 +71,7 @@
|
|
|
68
71
|
"react": ">=16"
|
|
69
72
|
},
|
|
70
73
|
"scripts": {
|
|
71
|
-
"start": "rollup -c rollup.config.app.js -w",
|
|
74
|
+
"start": "npm run build && rollup -c rollup.config.app.js -w",
|
|
72
75
|
"build": "rollup -c",
|
|
73
76
|
"test": "jest",
|
|
74
77
|
"lint": "eslint ./src",
|
package/dist/Descope.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '@descope/web-component';
|
|
3
|
-
import { DescopeCustomElement } from './types';
|
|
4
|
-
interface PropsType {
|
|
5
|
-
projectId: string;
|
|
6
|
-
flowId: string;
|
|
7
|
-
baseUrl?: string;
|
|
8
|
-
onSuccess?: DescopeCustomElement['onsuccess'];
|
|
9
|
-
onError?: DescopeCustomElement['onerror'];
|
|
10
|
-
}
|
|
11
|
-
declare const Descope: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<HTMLElement>>;
|
|
12
|
-
export default Descope;
|
package/dist/Descope.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useImperativeHandle, useEffect } from 'react';
|
|
2
|
-
import '@descope/web-component';
|
|
3
|
-
|
|
4
|
-
const Descope = React.forwardRef(({ projectId, flowId, baseUrl, onSuccess, onError }, ref) => {
|
|
5
|
-
const innerRef = useRef();
|
|
6
|
-
useImperativeHandle(ref, () => innerRef.current);
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const ele = innerRef.current;
|
|
9
|
-
if (onError)
|
|
10
|
-
ele?.addEventListener('error', onError);
|
|
11
|
-
if (onSuccess)
|
|
12
|
-
ele?.addEventListener('success', onSuccess);
|
|
13
|
-
return () => {
|
|
14
|
-
if (onError)
|
|
15
|
-
ele?.removeEventListener('error', onError);
|
|
16
|
-
if (onSuccess)
|
|
17
|
-
ele?.removeEventListener('success', onSuccess);
|
|
18
|
-
};
|
|
19
|
-
}, [innerRef, onError, onSuccess]);
|
|
20
|
-
return React.createElement("descope-wc", { "project-id": projectId, "flow-id": flowId, "base-url": baseUrl, ref: innerRef });
|
|
21
|
-
});
|
|
22
|
-
Descope.defaultProps = {
|
|
23
|
-
onError: undefined,
|
|
24
|
-
onSuccess: undefined,
|
|
25
|
-
baseUrl: undefined
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { Descope as default };
|
package/dist/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React, { DOMAttributes } from 'react';
|
|
2
|
-
import DescopeWc from '@descope/web-component';
|
|
3
|
-
declare global {
|
|
4
|
-
namespace JSX {
|
|
5
|
-
interface IntrinsicElements {
|
|
6
|
-
['descope-wc']: DescopeCustomElement;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export declare type CustomEvents<K extends string> = {
|
|
11
|
-
[key in K]: (event: CustomEvent) => void;
|
|
12
|
-
};
|
|
13
|
-
export declare type CustomElement<T, K extends string = ''> = Partial<T & DOMAttributes<T> & {
|
|
14
|
-
children: React.ReactChild;
|
|
15
|
-
ref: React.Ref<HTMLElement>;
|
|
16
|
-
} & CustomEvents<`on${K}`>>;
|
|
17
|
-
export declare type DescopeCustomElement = CustomElement<DescopeWc, 'success' | 'error'>;
|