@descope/react-sdk 0.0.52-alpha.3 → 0.0.52-alpha.5

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 CHANGED
@@ -24,6 +24,28 @@ const AppRoot = () => {
24
24
  }
25
25
  ```
26
26
  #### Use Descope to render specific flow
27
+ You can use default flows or provide flow id directly to the Descope component
28
+
29
+ ##### Default flows
30
+
31
+ ```js
32
+ // you can choose flow to run from the following
33
+ // import { SignIn } from '@descope/react-sdk'
34
+ // import { SignUp } from '@descope/react-sdk'
35
+ import { SignUpOrIn } from '@descope/react-sdk'
36
+
37
+ const App = () => {
38
+ return (
39
+ {...}
40
+ <SignUpOrIn
41
+ onSuccess={(e) => console.log('Logged in!')}
42
+ onError={(e) => console.log('Could not logged in!')}
43
+ />
44
+ )
45
+ }
46
+ ```
47
+
48
+ ##### Provide flow id
27
49
 
28
50
  ```js
29
51
  import { Descope } from '@descope/react-sdk'
@@ -35,10 +57,19 @@ const App = () => {
35
57
  flowId="myFlowId"
36
58
  onSuccess={(e) => console.log('Logged in!')}
37
59
  onError={(e) => console.log('Could not logged in!')}
38
- >
60
+ />
39
61
  )
40
62
  }
41
63
  ```
42
64
 
43
- TODO:
44
- - decide about the callbacks event data & structure
65
+ ## Contributing to this project
66
+ In order to use this repo locally
67
+ - Clone this repository
68
+ - Navigate to repository directory
69
+ - Run `npm i`
70
+ - Edit `src/app/index.tsx` in the following way
71
+ - Set `projectId` prop - replace `<project-id>` with your project id
72
+ - Set `flowId` prop - Replace `<flow-id>` (for example - `sign-up-or-in`)
73
+ - Optional - set a different `baseUrl` (for example - `http://localhost:8000`)
74
+ - Run `npm run start`
75
+ - Go to `http://localhost:3000/` and start flow
package/dist/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
- import React, { DOMAttributes, FC } from 'react';
1
+ /// <reference types="react" />
2
+ import React, { FC, DOMAttributes } from 'react';
2
3
  import DescopeWc from '@descope/web-component';
3
4
 
5
+ interface IAuthProviderProps {
6
+ projectId: string;
7
+ baseUrl?: string;
8
+ children?: JSX.Element;
9
+ }
10
+ declare const AuthProvider: FC<IAuthProviderProps>;
11
+
4
12
  declare global {
5
13
  namespace JSX {
6
14
  interface IntrinsicElements {
@@ -39,6 +47,18 @@ interface User {
39
47
  verifiedPhone?: boolean;
40
48
  tenants?: string[];
41
49
  }
50
+ interface DescopeProps {
51
+ flowId: string;
52
+ onSuccess?: DescopeCustomElement['onsuccess'];
53
+ onError?: DescopeCustomElement['onerror'];
54
+ }
55
+ declare type DefaultFlowProps = Omit<DescopeProps, 'flowId'>;
56
+
57
+ declare const SignInFlow: (props: DefaultFlowProps) => JSX.Element;
58
+ declare const SignUpFlow: (props: DefaultFlowProps) => JSX.Element;
59
+ declare const SignUpOrInFlow: (props: DefaultFlowProps) => JSX.Element;
60
+
61
+ declare const Descope: React.ForwardRefExoticComponent<DescopeProps & React.RefAttributes<HTMLElement>>;
42
62
 
43
63
  declare const useAuth: () => {
44
64
  projectId: string;
@@ -48,18 +68,4 @@ declare const useAuth: () => {
48
68
  sessionToken: string;
49
69
  };
50
70
 
51
- interface PropsType {
52
- flowId: string;
53
- onSuccess?: DescopeCustomElement['onsuccess'];
54
- onError?: DescopeCustomElement['onerror'];
55
- }
56
- declare const Descope: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<HTMLElement>>;
57
-
58
- interface IAuthProviderProps {
59
- projectId: string;
60
- baseUrl?: string;
61
- children?: JSX.Element;
62
- }
63
- declare const AuthProvider: FC<IAuthProviderProps>;
64
-
65
- export { AuthProvider, Descope, useAuth };
71
+ export { AuthProvider, Descope, SignInFlow, SignUpFlow, SignUpOrInFlow, useAuth };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import e,{useMemo as t,useRef as r,useImperativeHandle as s,useCallback as o,useEffect as n,useState as c}from"react";import"@descope/web-component";const d=e.createContext(void 0),i=()=>{const r=e.useContext(d);if(!r)throw Error("You can only use useAuth in the context of <AuthProvider />");const{projectId:s,baseUrl:o,authenticated:n,user:c,sessionToken:i}=r;return t((()=>({projectId:s,baseUrl:o,authenticated:n,user:c,sessionToken:i})),[s,o,n,c,i])},u=e.forwardRef((({flowId:t,onSuccess:c,onError:i},u)=>{const a=r();s(u,(()=>a.current));const{projectId:l,baseUrl:p,setAuthenticated:v,setUser:h,setSessionToken:f}=e.useContext(d),E=o((e=>{h(e.detail?.user),v(!0),f(e.detail?.sessionJwt),c&&c(e)}),[h,v,c]);return n((()=>{const e=a.current;return e?.addEventListener("success",E),i&&e?.addEventListener("error",i),()=>{i&&e?.removeEventListener("error",i),e?.removeEventListener("success",E)}}),[a,i,E]),e.createElement("descope-wc",{"project-id":l,"flow-id":t,"base-url":p,ref:a})}));u.defaultProps={onError:void 0,onSuccess:void 0};const a=({projectId:r,baseUrl:s,children:o})=>{const[n,i]=c(!1),[u,a]=c({}),[l,p]=c(""),v=t((()=>({projectId:r,baseUrl:s,user:u,authenticated:n,sessionToken:l,setUser:a,setAuthenticated:i,setSessionToken:p})),[n,u,r,s]);return e.createElement(d.Provider,{value:v},o)};a.defaultProps={baseUrl:"",children:void 0};export{a as AuthProvider,u as Descope,i as useAuth};
1
+ import e,{useState as t,useMemo as r,useRef as s,useImperativeHandle as o,useCallback as n,useEffect as c}from"react";import"@descope/web-component";const i=e.createContext(void 0),d=({projectId:s,baseUrl:o,children:n})=>{const[c,d]=t(!1),[u,a]=t({}),[l,p]=t(""),f=r((()=>({projectId:s,baseUrl:o,user:u,authenticated:c,sessionToken:l,setUser:a,setAuthenticated:d,setSessionToken:p})),[c,u,s,o]);return e.createElement(i.Provider,{value:f},n)};d.defaultProps={baseUrl:"",children:void 0};const u=e.forwardRef((({flowId:t,onSuccess:r,onError:d},u)=>{const a=s();o(u,(()=>a.current));const{projectId:l,baseUrl:p,setAuthenticated:f,setUser:v,setSessionToken:E}=e.useContext(i),h=n((e=>{v(e.detail?.user),f(!0),E(e.detail?.sessionJwt),r&&r(e)}),[v,f,r]);return c((()=>{const e=a.current;return e?.addEventListener("success",h),d&&e?.addEventListener("error",d),()=>{d&&e?.removeEventListener("error",d),e?.removeEventListener("success",h)}}),[a,d,h]),e.createElement("descope-wc",{"project-id":l,"flow-id":t,"base-url":p,ref:a})}));u.defaultProps={onError:void 0,onSuccess:void 0};const a=t=>e.createElement(u,{...t,flowId:"sign-in"}),l=t=>e.createElement(u,{...t,flowId:"sign-up"}),p=t=>e.createElement(u,{...t,flowId:"sign-up-or-in"}),f=()=>{const t=e.useContext(i);if(!t)throw Error("You can only use useAuth in the context of <AuthProvider />");const{projectId:s,baseUrl:o,authenticated:n,user:c,sessionToken:d}=t;return r((()=>({projectId:s,baseUrl:o,authenticated:n,user:c,sessionToken:d})),[s,o,n,c,d])};export{d as AuthProvider,u as Descope,a as SignInFlow,l as SignUpFlow,p as SignUpOrInFlow,f as useAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/react-sdk",
3
- "version": "0.0.52-alpha.3",
3
+ "version": "0.0.52-alpha.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Descope React SDK",
@@ -13,7 +13,7 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@descope/web-component": "^0.0.26-alpha.4"
16
+ "@descope/web-component": "^0.0.26-alpha.7"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@babel/core": "7.18.9",