@descope/react-sdk 0.0.52-alpha.16 → 0.0.52-alpha.17

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Descope
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -145,16 +145,31 @@ const App = () => {
145
145
  }
146
146
  ```
147
147
 
148
- ## Contributing to this project
148
+ ## Run a local example
149
149
 
150
- In order to use this repo locally
150
+ There is a simple app that uses Descope React SDK, with two routes
151
+
152
+ - Home
153
+ - Login
154
+
155
+ In order to run this app locally, do the following steps:
151
156
 
152
157
  - Clone this repository
153
158
  - Navigate to repository directory
154
159
  - Run `npm i`
155
- - Edit `src/app/index.tsx` in the following way
156
- - Set `projectId` prop - replace `<project-id>` with your project id
157
- - Set `flowId` prop - Replace `<flow-id>` (for example - `sign-up-or-in`)
158
- - Optional - set a different `baseUrl` (for example - `http://localhost:8000`)
160
+ - Create a `.env` file with the following variables (or alternatively export them manually):
161
+
162
+ ```env
163
+ // .env
164
+ # Your project id
165
+ DESCOPE_PROJECT_ID=<project-id>
166
+ # Flow id to run, e.g. sign-up-or-in
167
+ DESCOPE_FLOW_ID=<flow-id>
168
+ # Optional - Descope base url, e.g. http://localhost:8000
169
+ DESCOPE_BASE_URL=<base-url>
170
+ ```
171
+
159
172
  - Run `npm run start`
160
- - Go to `http://localhost:3000/` and start flow
173
+ - Go to `http://localhost:3000/` and press the "Start Flow" button
174
+
175
+ Note: if you change env file (for example, change DESCOPE_PROJECT_ID), you need to rerun `npm run start`
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import e from"@descope/web-js-sdk";import o,{useState as t,useMemo as r,useEffect as s,useRef as n,useImperativeHandle as c,useCallback as i}from"react";import"@descope/web-component";const u=o.createContext(void 0),d=({projectId:n,baseUrl:c,children:i})=>{const[d,a]=t({}),[l,p]=t(""),f=r((()=>{if(n)return e({projectId:n,baseUrl:c,hooks:{beforeRequest:e=>{const o=e;return o.headers={...o.headers,"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.52-alpha.16"},o}}})}),[n,c]);s((()=>{if(!f)return;const e=f.onSessionTokenChange(p),o=f.onUserChange(a);return()=>{e?.(),o?.()}}),[f]);const m=r((()=>({sdk:f,projectId:n,baseUrl:c,user:d,sessionToken:l,setUser:a,setSessionToken:p})),[l,d,n,c]);return o.createElement(u.Provider,{value:m},i)};d.defaultProps={baseUrl:"",children:void 0};const a=o.forwardRef((({flowId:e,onSuccess:t,onError:r,tenant:d},a)=>{const l=n();c(a,(()=>l.current));const{projectId:p,baseUrl:f,setUser:m,setSessionToken:h}=o.useContext(u),w=i((e=>{m(e.detail?.user);const o=e.detail?.sessionJwt;h(o),t&&t(e)}),[m,h,t]);return s((()=>{const e=l.current;return e?.addEventListener("success",w),r&&e?.addEventListener("error",r),()=>{r&&e?.removeEventListener("error",r),e?.removeEventListener("success",w)}}),[l,r,w]),o.createElement("descope-wc",{"project-id":p,"flow-id":e,"base-url":f,ref:l,tenant:d})}));a.defaultProps={onError:void 0,onSuccess:void 0};const l=e=>o.createElement(a,{...e,flowId:"sign-in"}),p=e=>o.createElement(a,{...e,flowId:"sign-up"}),f=e=>o.createElement(a,{...e,flowId:"sign-up-or-in"}),m=e=>(...o)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...o)},h=()=>{const e=o.useContext(u);if(!e)throw Error("You can only use 'useAuth' in the context of <AuthProvider />");const{user:t,sessionToken:s,sdk:n}=e,c=i(m(n?.logoutAll),[n]),d=i(m(n?.logout),[n]),a=i(m(n?.me),[n]),l=i(m(n?.getJwtPermissions),[n]),p=i(m(n?.getJwtRoles),[n]);return r((()=>({authenticated:!!s,user:t,sessionToken:s,logoutAll:c,logout:d,me:a,getJwtPermissions:l,getJwtRoles:p})),[t,s,n])};export{d as AuthProvider,a as Descope,l as SignInFlow,p as SignUpFlow,f as SignUpOrInFlow,h as useAuth};
1
+ import e from"@descope/web-js-sdk";import o,{useState as t,useMemo as r,useEffect as s,useRef as n,useImperativeHandle as c,useCallback as i}from"react";import"@descope/web-component";const u=o.createContext(void 0),d=({projectId:n,baseUrl:c,children:i})=>{const[d,a]=t({}),[l,p]=t(""),f=r((()=>{if(n)return e({projectId:n,baseUrl:c,hooks:{beforeRequest:e=>{const o=e;return o.headers={...o.headers,"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.52-alpha.17"},o}}})}),[n,c]);s((()=>{if(!f)return;const e=f.onSessionTokenChange(p),o=f.onUserChange(a);return()=>{e?.(),o?.()}}),[f]);const m=r((()=>({sdk:f,projectId:n,baseUrl:c,user:d,sessionToken:l,setUser:a,setSessionToken:p})),[l,d,n,c]);return o.createElement(u.Provider,{value:m},i)};d.defaultProps={baseUrl:"",children:void 0};const a=o.forwardRef((({flowId:e,onSuccess:t,onError:r,tenant:d},a)=>{const l=n();c(a,(()=>l.current));const{projectId:p,baseUrl:f,setUser:m,setSessionToken:h}=o.useContext(u),w=i((e=>{m(e.detail?.user);const o=e.detail?.sessionJwt;h(o),t&&t(e)}),[m,h,t]);return s((()=>{const e=l.current;return e?.addEventListener("success",w),r&&e?.addEventListener("error",r),()=>{r&&e?.removeEventListener("error",r),e?.removeEventListener("success",w)}}),[l,r,w]),o.createElement("descope-wc",{"project-id":p,"flow-id":e,"base-url":f,ref:l,tenant:d})}));a.defaultProps={onError:void 0,onSuccess:void 0};const l=e=>o.createElement(a,{...e,flowId:"sign-in"}),p=e=>o.createElement(a,{...e,flowId:"sign-up"}),f=e=>o.createElement(a,{...e,flowId:"sign-up-or-in"}),m=e=>(...o)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...o)},h=()=>{const e=o.useContext(u);if(!e)throw Error("You can only use 'useAuth' in the context of <AuthProvider />");const{user:t,sessionToken:s,sdk:n}=e,c=i(m(n?.logoutAll),[n]),d=i(m(n?.logout),[n]),a=i(m(n?.me),[n]),l=i(m(n?.getJwtPermissions),[n]),p=i(m(n?.getJwtRoles),[n]);return r((()=>({authenticated:!!s,user:t,sessionToken:s,logoutAll:c,logout:d,me:a,getJwtPermissions:l,getJwtRoles:p})),[t,s,n])};export{d as AuthProvider,a as Descope,l as SignInFlow,p as SignUpFlow,f as SignUpOrInFlow,h as useAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/react-sdk",
3
- "version": "0.0.52-alpha.16",
3
+ "version": "0.0.52-alpha.17",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Descope React SDK",
@@ -40,10 +40,10 @@
40
40
  "eslint-import-resolver-typescript": "2.7.1",
41
41
  "eslint-plugin-import": "2.26.0",
42
42
  "eslint-plugin-jest": "26.9.0",
43
- "eslint-plugin-jest-dom": "4.0.2",
43
+ "eslint-plugin-jest-dom": "4.0.3",
44
44
  "eslint-plugin-jest-formatting": "3.1.0",
45
45
  "eslint-plugin-jsx-a11y": "6.6.1",
46
- "eslint-plugin-n": "15.3.0",
46
+ "eslint-plugin-n": "15.5.1",
47
47
  "eslint-plugin-no-only-tests": "2.6.0",
48
48
  "eslint-plugin-prefer-arrow": "1.2.3",
49
49
  "eslint-plugin-prettier": "4.2.1",
@@ -62,6 +62,7 @@
62
62
  "rollup-plugin-browsersync": "^1.3.3",
63
63
  "rollup-plugin-define": "^1.0.1",
64
64
  "rollup-plugin-delete": "^2.0.0",
65
+ "rollup-plugin-dotenv": "^0.4.1",
65
66
  "rollup-plugin-dts": "^4.2.2",
66
67
  "rollup-plugin-livereload": "^2.0.5",
67
68
  "rollup-plugin-serve": "^1.1.0",