@descope/react-sdk 0.0.52-alpha.7 → 0.0.52-alpha.82
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 +21 -0
- package/README.md +174 -30
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/index.d.ts +600 -32
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +103 -78
- package/dist/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 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
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
# @descope/react-sdk
|
|
2
|
+
|
|
2
3
|
This library lets you consume your login pages created by Descope console-app in your application
|
|
3
4
|
Under the hood, it uses [web-js-sdk](https://github.com/descope/web-js-sdk)
|
|
4
5
|
|
|
5
6
|
## Usage
|
|
7
|
+
|
|
6
8
|
### Install the package
|
|
9
|
+
|
|
7
10
|
```bash
|
|
8
11
|
npm install @descope/react-sdk
|
|
9
12
|
```
|
|
10
13
|
|
|
11
14
|
### Render it in your application
|
|
15
|
+
|
|
12
16
|
#### Wrap your app with Auth Provider
|
|
17
|
+
|
|
13
18
|
```js
|
|
14
|
-
import { AuthProvider } from '@descope/react-sdk'
|
|
19
|
+
import { AuthProvider } from '@descope/react-sdk';
|
|
15
20
|
|
|
16
21
|
const AppRoot = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
}
|
|
22
|
+
return (
|
|
23
|
+
<AuthProvider projectId="my-project-id">
|
|
24
|
+
<App />
|
|
25
|
+
</AuthProvider>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
25
28
|
```
|
|
29
|
+
|
|
26
30
|
#### Use Descope to render specific flow
|
|
27
|
-
You can use default flows or provide flow id directly to the Descope component
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
You can use **default flows** or **provide flow id** directly to the Descope component
|
|
33
|
+
|
|
34
|
+
##### 1. Default flows
|
|
30
35
|
|
|
31
36
|
```js
|
|
37
|
+
import { SignInFlow } from '@descope/react-sdk'
|
|
32
38
|
// you can choose flow to run from the following
|
|
33
|
-
// import {
|
|
34
|
-
// import {
|
|
35
|
-
import { SignUpOrIn } from '@descope/react-sdk'
|
|
39
|
+
// import { SignUpFlow } from '@descope/react-sdk'
|
|
40
|
+
// import { SignUpOrInFlow } from '@descope/react-sdk'
|
|
36
41
|
|
|
37
42
|
const App = () => {
|
|
38
43
|
return (
|
|
39
44
|
{...}
|
|
40
|
-
<
|
|
45
|
+
<SignInFlow
|
|
41
46
|
onSuccess={(e) => console.log('Logged in!')}
|
|
42
47
|
onError={(e) => console.log('Could not logged in!')}
|
|
43
48
|
/>
|
|
@@ -45,7 +50,7 @@ const App = () => {
|
|
|
45
50
|
}
|
|
46
51
|
```
|
|
47
52
|
|
|
48
|
-
##### Provide flow id
|
|
53
|
+
##### 2. Provide flow id
|
|
49
54
|
|
|
50
55
|
```js
|
|
51
56
|
import { Descope } from '@descope/react-sdk'
|
|
@@ -53,23 +58,162 @@ import { Descope } from '@descope/react-sdk'
|
|
|
53
58
|
const App = () => {
|
|
54
59
|
return (
|
|
55
60
|
{...}
|
|
56
|
-
<Descope
|
|
57
|
-
flowId="
|
|
61
|
+
<Descope
|
|
62
|
+
flowId="my-flow-id"
|
|
58
63
|
onSuccess={(e) => console.log('Logged in!')}
|
|
59
|
-
onError={(e) => console.log('Could not logged in
|
|
64
|
+
onError={(e) => console.log('Could not logged in')}
|
|
65
|
+
// theme can be "light" or "dark". If empty, Descope will use the OS theme
|
|
66
|
+
// theme="light"
|
|
67
|
+
|
|
68
|
+
// debug can be set to true to enable debug mode
|
|
69
|
+
// debug={true}
|
|
60
70
|
/>
|
|
61
71
|
)
|
|
62
72
|
}
|
|
63
73
|
```
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
#### Use the `useDescope`, `useSession` and `useUser` hooks in your components in order to get authentication state, user details and utilities
|
|
76
|
+
|
|
77
|
+
This can be helpful to implement application-specific logic. Examples:
|
|
78
|
+
|
|
79
|
+
- Render different components if current session is authenticated
|
|
80
|
+
- Render user's content
|
|
81
|
+
- Logout button
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { useDescope, useSession, useUser } from '@descope/react-sdk'
|
|
85
|
+
|
|
86
|
+
const App = () => {
|
|
87
|
+
// NOTE - `useDescope`, `useSession`, `useUser` should be used inside `AuthProvider` context,
|
|
88
|
+
// and will throw an exception if this requirement is not met
|
|
89
|
+
const { isAuthenticated, isSessionLoading } = useSession()
|
|
90
|
+
const { user, isUserLoading } = useUser()
|
|
91
|
+
const { logout } = useDescope()
|
|
92
|
+
|
|
93
|
+
if(isSessionLoading || isUserLoading){
|
|
94
|
+
return <p>Loading...</p>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if(isAuthenticated){
|
|
98
|
+
return (
|
|
99
|
+
<p>Hello ${user.name}</p>
|
|
100
|
+
<button onClick={logout}>Logout</div>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return <p>You are not logged in</p>
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Session token server validation (pass session token to server API)
|
|
109
|
+
|
|
110
|
+
When developing a full-stack application, it is common to have private server API which requires a valid session token:
|
|
111
|
+
|
|
112
|
+

|
|
113
|
+
|
|
114
|
+
Note: Descope also provides server-side SDKs in various languages (NodeJS, Go, Python, etc). Descope's server SDKs have out-of-the-box session validation API that supports the options described bellow. To read more about session validation, Read [this section](https://docs.descope.com/guides/gettingstarted/#session-validation) in Descope documentation.
|
|
115
|
+
|
|
116
|
+
There are 2 ways to achieve that:
|
|
117
|
+
|
|
118
|
+
1. Using `getSessionToken` to get the token, and pass it on the `Authorization` Header (Recommended)
|
|
119
|
+
2. Passing `sessionTokenViaCookie` boolean prop to the `AuthProvider` component (Use cautiously, session token may grow, especially in cases of using authorization, or adding custom claim)
|
|
120
|
+
|
|
121
|
+
##### 1. Using `getSessionToken` to get the token
|
|
122
|
+
|
|
123
|
+
An example for api function, and passing the token on the `Authorization` header:
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
import { getSessionToken } from '@descope/react-sdk';
|
|
127
|
+
|
|
128
|
+
// fetch data using back
|
|
129
|
+
// Note: Descope backend SDKs support extracting session token from the Authorization header
|
|
130
|
+
export const fetchData = async () => {
|
|
131
|
+
const sessionToken = getSessionToken();
|
|
132
|
+
const res = await fetch('/path/to/server/api', {
|
|
133
|
+
headers: {
|
|
134
|
+
Authorization: `Bearer ${sessionToken}`
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
// ... use res
|
|
138
|
+
};
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
An example for component that uses `fetchData` function from above
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
// Component code
|
|
145
|
+
import { fetchData } from 'path/to/api/file'
|
|
146
|
+
import { useCallback } from 'react'
|
|
147
|
+
|
|
148
|
+
const Component = () => {
|
|
149
|
+
const onClick = useCallback(() => {
|
|
150
|
+
fetchData()
|
|
151
|
+
},[])
|
|
152
|
+
return (
|
|
153
|
+
{...}
|
|
154
|
+
{
|
|
155
|
+
// button that triggers an API that may use session token
|
|
156
|
+
<button onClick={onClick}>Click Me</div>
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
##### 2. Passing `sessionTokenViaCookie` boolean prop to the `AuthProvider`
|
|
163
|
+
|
|
164
|
+
Passing `sessionTokenViaCookie` prop to `AuthProvider` component. Descope SDK will automatically store session token on the `DS` cookie.
|
|
165
|
+
|
|
166
|
+
Note: Use this option if session token will stay small (less than 1k). Session token can grow, especially in cases of using authorization, or adding custom claims
|
|
167
|
+
|
|
168
|
+
Example:
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
import { AuthProvider } from '@descope/react-sdk';
|
|
172
|
+
|
|
173
|
+
const AppRoot = () => {
|
|
174
|
+
return (
|
|
175
|
+
<AuthProvider projectId="my-project-id" sessionTokenViaCookie>
|
|
176
|
+
<App />
|
|
177
|
+
</AuthProvider>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Now, whenever you call `fetch`, the cookie will automatically be sent with the request. Descope backend SDKs also support extracting the token from the `DS` cookie.
|
|
183
|
+
|
|
184
|
+
## Run a local example
|
|
185
|
+
|
|
186
|
+
There is a simple app that uses Descope React SDK, with two routes
|
|
187
|
+
|
|
188
|
+
- Home
|
|
189
|
+
- Login
|
|
190
|
+
|
|
191
|
+
In order to run this app locally, do the following steps:
|
|
192
|
+
|
|
193
|
+
- Clone this repository
|
|
194
|
+
- Navigate to repository directory
|
|
195
|
+
- Run `npm i`
|
|
196
|
+
- Create a `.env` file with the following variables (or alternatively export them manually):
|
|
197
|
+
|
|
198
|
+
```env
|
|
199
|
+
// .env
|
|
200
|
+
# Your project id
|
|
201
|
+
DESCOPE_PROJECT_ID=<project-id>
|
|
202
|
+
# Flow id to run, e.g. sign-up-or-in
|
|
203
|
+
DESCOPE_FLOW_ID=<flow-id>
|
|
204
|
+
# Optional - Descope base url, e.g. http://localhost:8000
|
|
205
|
+
DESCOPE_BASE_URL=<base-url>
|
|
206
|
+
# Optional - Debug mode
|
|
207
|
+
DESCOPE_DEBUG_MODE=<debug-mode>
|
|
208
|
+
# Optional - Theme, can be "light", "dark" or "os" (Auto select based on the OS theme settings). Default is "light"
|
|
209
|
+
DESCOPE_THEME=<theme>
|
|
210
|
+
# Optional - Telemetry key provided by Descope Inc
|
|
211
|
+
DESCOPE_TELEMETRY_KEY=<telemetry-key>
|
|
212
|
+
# Optional - Step-Up flow id. If exists, The home page of a logged-in user will show a step-up button
|
|
213
|
+
DESCOPE_STEP_UP_FLOW_ID=step-up
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- Run `npm run start`
|
|
217
|
+
- Go to `http://localhost:3000/` and press the "Start Flow" button
|
|
218
|
+
|
|
219
|
+
Note: if you change env file (for example, change DESCOPE_PROJECT_ID), you need to rerun `npm run start`
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@descope/web-js-sdk");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var o=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var r=s(e),n=s(t);const u=r.default.createContext(void 0),a={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.52-alpha.82"},i=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},l=e=>(...t)=>{let s;try{s=e(...t)}catch(e){console.error(e)}return s};let c;const d=e=>{const t=n.default({...e,persistTokens:!0,autoRefresh:!0});return c=t,t};c=d({projectId:"temp pid"});const f=()=>c?.getSessionToken(),p=l(((e=f(),t)=>c?.getJwtPermissions(e,t))),g=l(((e=f(),t)=>c?.getJwtRoles(e,t)));const m=({projectId:t,baseUrl:s,sessionTokenViaCookie:o,children:n})=>{const[l,c]=e.useState(),[f,p]=e.useState(),[g,m]=e.useState(!1),[h,k]=e.useState(!1),b=(({projectId:t,baseUrl:s,sessionTokenViaCookie:o})=>e.useMemo((()=>{if(t)return d({projectId:t,baseUrl:s,sessionTokenViaCookie:o,baseHeaders:a,persistToken:!0,autoRefresh:!0})}),[t,s,o]))({projectId:t,baseUrl:s,sessionTokenViaCookie:o});e.useEffect((()=>{if(b){const e=b.onSessionTokenChange(p),t=b.onUserChange(c);return()=>{e(),t()}}}),[b]);const v=e.useCallback((()=>{k(!0),i(b?.refresh)().then((()=>{k(!1)}))}),[b]),w=e.useCallback((()=>{m(!0),i(b.me)().then((()=>{m(!1)}))}),[b]),S=e.useCallback(i(b?.logoutAll),[b]),y=e.useCallback(i(b?.logout),[b]),E=e.useMemo((()=>({fetchUser:w,user:l,isUserLoading:g,fetchSession:v,session:f,isSessionLoading:h,logout:y,logoutAll:S,projectId:t,baseUrl:s,setUser:c,setSession:p,sdk:b})),[w,l,g,v,f,h,y,S,t,s,c,p,b]);return r.default.createElement(u.Provider,{value:E},n)};m.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const h=e.lazy((async()=>((await Promise.resolve().then((function(){return o(require("@descope/web-component"))}))).default.sdkConfigOverrides={baseHeaders:a},{default:({projectId:e,flowId:t,baseUrl:s,innerRef:o,tenant:n,theme:u,debug:a,telemetryKey:i})=>r.default.createElement("descope-wc",{"project-id":e,"flow-id":t,"base-url":s,ref:o,tenant:n,theme:u,debug:a,telemetryKey:i})}))),k=r.default.forwardRef((({flowId:t,onSuccess:s,onError:o,tenant:n,theme:a,debug:i,telemetryKey:l},c)=>{const[d,f]=e.useState(null);e.useImperativeHandle(c,(()=>d));const{projectId:p,baseUrl:g,setUser:m,setSession:k,sdk:b}=r.default.useContext(u),v=e.useCallback((async e=>{m(e.detail?.user);const t=e.detail?.sessionJwt;k(t),await b.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),s&&s(e)}),[m,k,s]);return e.useEffect((()=>{const e=d;return e?.addEventListener("success",v),o&&e?.addEventListener("error",o),()=>{o&&e?.removeEventListener("error",o),e?.removeEventListener("success",v)}}),[d,o,v]),r.default.createElement("form",null,r.default.createElement(e.Suspense,{fallback:null},r.default.createElement(h,{projectId:p,flowId:t,baseUrl:g,innerRef:f,tenant:n,theme:a,debug:i,telemetryKey:l})))}));k.defaultProps={onError:void 0,onSuccess:void 0};var b=()=>{const t=e.useContext(u);if(!t)throw Error("You can only use this hook in the context of <AuthProvider />");return t};exports.AuthProvider=m,exports.Descope=k,exports.SignInFlow=e=>r.default.createElement(k,{...e,flowId:"sign-in"}),exports.SignUpFlow=e=>r.default.createElement(k,{...e,flowId:"sign-up"}),exports.SignUpOrInFlow=e=>r.default.createElement(k,{...e,flowId:"sign-up-or-in"}),exports.getJwtPermissions=p,exports.getJwtRoles=g,exports.getRefreshToken=()=>c?.getRefreshToken(),exports.getSessionToken=f,exports.useDescope=()=>{const{logout:t,logoutAll:s}=b();return e.useMemo((()=>({logoutAll:s,logout:t})),[s,t])},exports.useSession=()=>{const{session:t,isSessionLoading:s,fetchSession:o}=b(),r=e.useRef(s);return e.useMemo((()=>{r.current=s}),[s]),e.useMemo((()=>{t||s||(r.current=!0)}),[o]),e.useEffect((()=>{t||s||o()}),[o]),{isSessionLoading:r.current,sessionToken:t,isAuthenticated:!!t}},exports.useUser=()=>{const{user:t,fetchUser:s,isUserLoading:o,session:r}=b(),[n,u]=e.useState(!1),a=e.useRef(o),i=e.useMemo((()=>!t&&!o&&r&&!n),[s,r,n]);return e.useMemo((()=>{a.current=o}),[o]),e.useMemo((()=>{i&&(a.current=!0)}),[i]),e.useEffect((()=>{i&&(u(!0),s())}),[i]),{isUserLoading:a.current,user:t}};
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/lib/hooks/Context.ts","../../src/lib/constants.ts","../../src/lib/utils.ts","../../src/lib/sdk.ts","../../src/lib/components/AuthProvider/AuthProvider.tsx","../../src/lib/components/AuthProvider/useSdk.ts","../../src/lib/components/Descope.tsx","../../src/lib/hooks/useContext.ts","../../src/lib/components/DefaultFlows.tsx","../../src/lib/hooks/useDescope.ts","../../src/lib/hooks/useSession.ts","../../src/lib/hooks/useUser.ts"],"sourcesContent":["import React from 'react';\nimport { IContext } from '../types';\n\nconst Context = React.createContext<IContext>(undefined);\n\nexport default Context;\n","declare const BUILD_VERSION: string;\n\n// eslint-disable-next-line import/prefer-default-export\nexport const baseHeaders = {\n\t'x-descope-sdk-name': 'react',\n\t'x-descope-sdk-version': BUILD_VERSION\n};\n","/**\n * Wrap a function with a validation that it exists\n * @param fn The function to wrap with the validation\n * @throws if function does not exist, an error with the relevant message will be thrown\n */\nexport const withValidation =\n\t<T extends Array<any>, U>(fn: (...args: T) => U) =>\n\t(...args: T): U => {\n\t\tif (!fn) {\n\t\t\tthrow Error(\n\t\t\t\t`You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`\n\t\t\t);\n\t\t}\n\t\treturn fn(...args);\n\t};\n\nexport const wrapInTry =\n\t<T extends Array<any>, U>(fn: (...args: T) => U) =>\n\t(...args: T): U => {\n\t\tlet res: U;\n\t\ttry {\n\t\t\tres = fn(...args);\n\t\t} catch (err) {\n\t\t\tconsole.error(err); // eslint-disable-line no-console\n\t\t}\n\t\treturn res;\n\t};\n","import createSdk from '@descope/web-js-sdk';\nimport { wrapInTry } from './utils';\n\ntype Sdk = ReturnType<typeof createSdkWrapper>;\nlet sdkInstance: Sdk;\n\nconst createSdkWrapper = <P extends Parameters<typeof createSdk>[0]>(\n\tconfig: P\n) => {\n\tconst sdk = createSdk({\n\t\t...config,\n\t\tpersistTokens: true,\n\t\tautoRefresh: true\n\t});\n\tsdkInstance = sdk;\n\n\treturn sdk;\n};\n\n/**\n * We want to make sure the getSessionToken fn is used only when persistTokens is on\n *\n * So we are keeping the SDK init in a single place,\n * and we are creating a temp instance in order to export the getSessionToken\n * even before the SDK was init\n */\nsdkInstance = createSdkWrapper({ projectId: 'temp pid' });\n\nexport const getSessionToken = () => sdkInstance?.getSessionToken();\nexport const getJwtPermissions = wrapInTry(\n\t(token = getSessionToken(), tenant?: string) =>\n\t\tsdkInstance?.getJwtPermissions(token, tenant)\n);\nexport const getJwtRoles = wrapInTry(\n\t(token = getSessionToken(), tenant?: string) =>\n\t\tsdkInstance?.getJwtRoles(token, tenant)\n);\nexport const getRefreshToken = () => sdkInstance?.getRefreshToken();\n\nexport default createSdkWrapper;\n","import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport useSdk from './useSdk';\nimport { withValidation } from '../../utils';\n\ninterface IAuthProviderProps {\n\tprojectId: string;\n\tbaseUrl?: string;\n\t// If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n\t// stored on local storage and can accessed with getSessionToken function\n\t// Use this option if session token will stay small (less than 1k)\n\t// NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n\tsessionTokenViaCookie?: boolean;\n\tchildren?: JSX.Element;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n\tprojectId,\n\tbaseUrl,\n\tsessionTokenViaCookie,\n\tchildren\n}) => {\n\tconst [user, setUser] = useState<User>();\n\tconst [session, setSession] = useState<string>();\n\n\tconst [isUserLoading, setIsUserLoading] = useState(false);\n\tconst [isSessionLoading, setIsSessionLoading] = useState(false);\n\n\tconst sdk = useSdk({ projectId, baseUrl, sessionTokenViaCookie });\n\n\tuseEffect(() => {\n\t\tif (sdk) {\n\t\t\tconst unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n\t\t\tconst unsubscribeUser = sdk.onUserChange(setUser);\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeSessionToken();\n\t\t\t\tunsubscribeUser();\n\t\t\t};\n\t\t}\n\t\treturn undefined;\n\t}, [sdk]);\n\n\tconst fetchSession = useCallback(() => {\n\t\tsetIsSessionLoading(true);\n\t\twithValidation(sdk?.refresh)().then(() => {\n\t\t\tsetIsSessionLoading(false);\n\t\t});\n\t}, [sdk]);\n\n\tconst fetchUser = useCallback(() => {\n\t\tsetIsUserLoading(true);\n\t\twithValidation(sdk.me)().then(() => {\n\t\t\tsetIsUserLoading(false);\n\t\t});\n\t}, [sdk]);\n\n\tconst logoutAll = useCallback(withValidation(sdk?.logoutAll), [sdk]);\n\n\tconst logout = useCallback(withValidation(sdk?.logout), [sdk]);\n\n\tconst value = useMemo<IContext>(\n\t\t() => ({\n\t\t\tfetchUser,\n\t\t\tuser,\n\t\t\tisUserLoading,\n\t\t\tfetchSession,\n\t\t\tsession,\n\t\t\tisSessionLoading,\n\t\t\tlogout,\n\t\t\tlogoutAll,\n\t\t\tprojectId,\n\t\t\tbaseUrl,\n\t\t\tsetUser,\n\t\t\tsetSession,\n\t\t\tsdk\n\t\t}),\n\t\t[\n\t\t\tfetchUser,\n\t\t\tuser,\n\t\t\tisUserLoading,\n\t\t\tfetchSession,\n\t\t\tsession,\n\t\t\tisSessionLoading,\n\t\t\tlogout,\n\t\t\tlogoutAll,\n\t\t\tprojectId,\n\t\t\tbaseUrl,\n\t\t\tsetUser,\n\t\t\tsetSession,\n\t\t\tsdk\n\t\t]\n\t);\n\treturn <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nAuthProvider.defaultProps = {\n\tbaseUrl: '',\n\tchildren: undefined,\n\tsessionTokenViaCookie: false\n};\n\nexport default AuthProvider;\n","import { useMemo } from 'react';\nimport { baseHeaders } from '../../constants';\nimport createSdk from '../../sdk';\n\ntype Config = Pick<\n\tParameters<typeof createSdk>[0],\n\t'projectId' | 'baseUrl' | 'sessionTokenViaCookie'\n>;\n\nexport default ({\n\tprojectId,\n\tbaseUrl,\n\tsessionTokenViaCookie\n}: Config): ReturnType<typeof createSdk> =>\n\tuseMemo(() => {\n\t\tif (!projectId) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn createSdk({\n\t\t\tprojectId,\n\t\t\tbaseUrl,\n\t\t\tsessionTokenViaCookie,\n\t\t\tbaseHeaders,\n\t\t\tpersistToken: true,\n\t\t\tautoRefresh: true\n\t\t});\n\t}, [projectId, baseUrl, sessionTokenViaCookie]);\n","import React, {\n\tlazy,\n\tSuspense,\n\tuseCallback,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseState\n} from 'react';\nimport Context from '../hooks/Context';\nimport { DescopeProps } from '../types';\nimport { baseHeaders } from '../constants';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst DescopeWC = lazy(async () => {\n\tconst module = await import('@descope/web-component');\n\t// we want to override the web-component base headers so we can tell that is was used via the React SDK\n\tmodule.default.sdkConfigOverrides = { baseHeaders };\n\n\treturn {\n\t\tdefault: ({\n\t\t\tprojectId,\n\t\t\tflowId,\n\t\t\tbaseUrl,\n\t\t\tinnerRef,\n\t\t\ttenant,\n\t\t\ttheme,\n\t\t\tdebug,\n\t\t\ttelemetryKey\n\t\t}) => (\n\t\t\t<descope-wc\n\t\t\t\tproject-id={projectId}\n\t\t\t\tflow-id={flowId}\n\t\t\t\tbase-url={baseUrl}\n\t\t\t\tref={innerRef}\n\t\t\t\ttenant={tenant}\n\t\t\t\ttheme={theme}\n\t\t\t\tdebug={debug}\n\t\t\t\ttelemetryKey={telemetryKey}\n\t\t\t/>\n\t\t)\n\t};\n});\n\nconst Descope = React.forwardRef<HTMLElement, DescopeProps>(\n\t({ flowId, onSuccess, onError, tenant, theme, debug, telemetryKey }, ref) => {\n\t\tconst [innerRef, setInnerRef] = useState(null);\n\n\t\tuseImperativeHandle(ref, () => innerRef);\n\n\t\tconst { projectId, baseUrl, setUser, setSession, sdk } =\n\t\t\tReact.useContext(Context);\n\n\t\tconst handleSuccess = useCallback(\n\t\t\tasync (e: CustomEvent) => {\n\t\t\t\tsetUser(e.detail?.user);\n\t\t\t\tconst sessionJwt = e.detail?.sessionJwt;\n\t\t\t\tsetSession(sessionJwt);\n\t\t\t\t// In order to make sure all the after-hooks are running with the success response\n\t\t\t\t// we are generating a fake response with the success data and calling the http client after hook fn with it\n\t\t\t\tawait sdk.httpClient.hooks.afterRequest(\n\t\t\t\t\t{} as any,\n\t\t\t\t\tnew Response(JSON.stringify(e.detail))\n\t\t\t\t);\n\t\t\t\tif (onSuccess) {\n\t\t\t\t\tonSuccess(e);\n\t\t\t\t}\n\t\t\t},\n\t\t\t[setUser, setSession, onSuccess]\n\t\t);\n\n\t\tuseEffect(() => {\n\t\t\tconst ele = innerRef;\n\t\t\tele?.addEventListener('success', handleSuccess);\n\t\t\tif (onError) ele?.addEventListener('error', onError);\n\n\t\t\treturn () => {\n\t\t\t\tif (onError) ele?.removeEventListener('error', onError);\n\n\t\t\t\tele?.removeEventListener('success', handleSuccess);\n\t\t\t};\n\t\t}, [innerRef, onError, handleSuccess]);\n\n\t\treturn (\n\t\t\t/**\n\t\t\t * in order to avoid redundant remounting of the WC, we are wrapping it with a form element\n\t\t\t * this workaround is done in order to support webauthn passkeys\n\t\t\t * it can be removed once this issue will be solved\n\t\t\t * https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2\n\t\t\t */\n\t\t\t<form>\n\t\t\t\t<Suspense fallback={null}>\n\t\t\t\t\t<DescopeWC\n\t\t\t\t\t\tprojectId={projectId}\n\t\t\t\t\t\tflowId={flowId}\n\t\t\t\t\t\tbaseUrl={baseUrl}\n\t\t\t\t\t\tinnerRef={setInnerRef}\n\t\t\t\t\t\ttenant={tenant}\n\t\t\t\t\t\ttheme={theme}\n\t\t\t\t\t\tdebug={debug}\n\t\t\t\t\t\ttelemetryKey={telemetryKey}\n\t\t\t\t\t/>\n\t\t\t\t</Suspense>\n\t\t\t</form>\n\t\t);\n\t}\n);\n\nDescope.defaultProps = {\n\tonError: undefined,\n\tonSuccess: undefined\n};\n\nexport default Descope;\n","import { useContext } from 'react';\nimport Context from './Context';\n\nexport default () => {\n\tconst ctx = useContext(Context);\n\tif (!ctx) {\n\t\tthrow Error(\n\t\t\t`You can only use this hook in the context of <AuthProvider />`\n\t\t);\n\t}\n\n\treturn ctx;\n};\n","import React from 'react';\nimport { DefaultFlowProps } from '../types';\nimport Descope from './Descope';\n\nexport const SignInFlow = (props: DefaultFlowProps) => (\n\t<Descope {...props} flowId=\"sign-in\" />\n);\n\nexport const SignUpFlow = (props: DefaultFlowProps) => (\n\t<Descope {...props} flowId=\"sign-up\" />\n);\n\nexport const SignUpOrInFlow = (props: DefaultFlowProps) => (\n\t<Descope {...props} flowId=\"sign-up-or-in\" />\n);\n","import { useMemo } from 'react';\nimport { IAuth } from '../types';\nimport useContext from './useContext';\n\nconst useDescope = (): IAuth => {\n\tconst { logout, logoutAll } = useContext();\n\n\treturn useMemo(\n\t\t() => ({\n\t\t\tlogoutAll,\n\t\t\tlogout\n\t\t}),\n\t\t[logoutAll, logout]\n\t);\n};\n\nexport default useDescope;\n","import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\n\nconst useSession = () => {\n\tconst { session, isSessionLoading, fetchSession } = useContext();\n\n\t// when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n\t// (and not only when receiving an update from the context)\n\tconst isLoading = useRef(isSessionLoading);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tisLoading.current = isSessionLoading;\n\t}, [isSessionLoading]);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tif (!session && !isSessionLoading) {\n\t\t\tisLoading.current = true;\n\t\t}\n\t}, [fetchSession]);\n\n\tuseEffect(() => {\n\t\tif (!session && !isSessionLoading) {\n\t\t\tfetchSession();\n\t\t}\n\t}, [fetchSession]);\n\n\treturn {\n\t\tisSessionLoading: isLoading.current,\n\t\tsessionToken: session,\n\t\tisAuthenticated: !!session\n\t};\n};\n\nexport default useSession;\n","import { useEffect, useMemo, useRef, useState } from 'react';\nimport useContext from './useContext';\n\nconst useUser = () => {\n\tconst { user, fetchUser, isUserLoading, session } = useContext();\n\tconst [isInit, setIsInit] = useState(false); // we want to get the user only in the first time we got a session\n\n\t// when session should be received, we want the return value of \"isUserLoading\" to be true starting from the first call\n\t// (and not only when receiving an update from the context)\n\tconst isLoading = useRef(isUserLoading);\n\n\tconst shouldFetchUser = useMemo(\n\t\t() => !user && !isUserLoading && session && !isInit,\n\t\t[fetchUser, session, isInit]\n\t);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tisLoading.current = isUserLoading;\n\t}, [isUserLoading]);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tif (shouldFetchUser) {\n\t\t\tisLoading.current = true;\n\t\t}\n\t}, [shouldFetchUser]);\n\n\tuseEffect(() => {\n\t\tif (shouldFetchUser) {\n\t\t\tsetIsInit(true);\n\t\t\tfetchUser();\n\t\t}\n\t}, [shouldFetchUser]);\n\n\treturn { isUserLoading: isLoading.current, user };\n};\n\nexport default useUser;\n"],"names":["Context","React","createContext","undefined","baseHeaders","withValidation","fn","args","Error","wrapInTry","res","err","console","error","sdkInstance","createSdkWrapper","config","sdk","createSdk","persistTokens","autoRefresh","projectId","getSessionToken","getJwtPermissions","token","tenant","getJwtRoles","AuthProvider","baseUrl","sessionTokenViaCookie","children","user","setUser","useState","session","setSession","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","useMemo","persistToken","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","fetchSession","useCallback","refresh","then","fetchUser","me","logoutAll","logout","value","createElement","Provider","defaultProps","DescopeWC","lazy","async","Promise","resolve","_interopNamespace","require","default","sdkConfigOverrides","flowId","innerRef","theme","debug","telemetryKey","ref","Descope","forwardRef","onSuccess","onError","setInnerRef","useImperativeHandle","useContext","handleSuccess","e","detail","sessionJwt","httpClient","hooks","afterRequest","Response","JSON","stringify","ele","addEventListener","removeEventListener","Suspense","fallback","ctx","props","getRefreshToken","isLoading","useRef","current","sessionToken","isAuthenticated","isInit","setIsInit","shouldFetchUser"],"mappings":"qfAGA,MAAMA,EAAUC,EAAAA,QAAMC,mBAAwBC,GCAjCC,EAAc,CAC1B,qBAAsB,QACtB,wBAAyB,mBCAbC,EACcC,GAC1B,IAAIC,KACH,IAAKD,EACJ,MAAME,MACL,0HAGF,OAAOF,KAAMC,EAAK,EAGPE,EACcH,GAC1B,IAAIC,KACH,IAAIG,EACJ,IACCA,EAAMJ,KAAMC,EAGZ,CAFC,MAAOI,GACRC,QAAQC,MAAMF,EACd,CACD,OAAOD,CAAG,ECrBZ,IAAII,EAEJ,MAAMC,EACLC,IAEA,MAAMC,EAAMC,EAAAA,QAAU,IAClBF,EACHG,eAAe,EACfC,aAAa,IAId,OAFAN,EAAcG,EAEPA,CAAG,EAUXH,EAAcC,EAAiB,CAAEM,UAAW,aAE/B,MAAAC,EAAkB,IAAMR,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EACnB,kBC7Bc,KACf,MAAMH,KAAEA,EAAIqB,UAAEA,EAAShB,cAAEA,EAAaF,QAAEA,GAAY+C,KAC7CwB,EAAQC,GAAazE,EAAQA,UAAC,GAI/BmE,EAAYC,SAAOjE,GAEnBuE,EAAkBnE,EAAOA,SAC9B,KAAOT,IAASK,GAAiBF,IAAYuE,GAC7C,CAACrD,EAAWlB,EAASuE,IAsBtB,OAlBAjE,EAAAA,SAAQ,KACP4D,EAAUE,QAAUlE,CAAa,GAC/B,CAACA,IAGJI,EAAAA,SAAQ,KACHmE,IACHP,EAAUE,SAAU,EACpB,GACC,CAACK,IAEJhE,EAAAA,WAAU,KACLgE,IACHD,GAAU,GACVtD,IACA,GACC,CAACuD,IAEG,CAAEvE,cAAegE,EAAUE,QAASvE,OAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,590 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React, { FC, DOMAttributes } from 'react';
|
|
3
3
|
import DescopeWc from '@descope/web-component';
|
|
4
|
+
import * as _descope_core_js_sdk from '@descope/core-js-sdk';
|
|
4
5
|
|
|
5
6
|
interface IAuthProviderProps {
|
|
6
7
|
projectId: string;
|
|
7
8
|
baseUrl?: string;
|
|
9
|
+
sessionTokenViaCookie?: boolean;
|
|
8
10
|
children?: JSX.Element;
|
|
9
11
|
}
|
|
10
12
|
declare const AuthProvider: FC<IAuthProviderProps>;
|
|
11
13
|
|
|
14
|
+
declare const createSdkWrapper: <P extends Omit<{
|
|
15
|
+
projectId: string;
|
|
16
|
+
logger?: {
|
|
17
|
+
debug: {
|
|
18
|
+
(...data: any[]): void;
|
|
19
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
20
|
+
};
|
|
21
|
+
log: {
|
|
22
|
+
(...data: any[]): void;
|
|
23
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
24
|
+
};
|
|
25
|
+
error: {
|
|
26
|
+
(...data: any[]): void;
|
|
27
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
28
|
+
};
|
|
29
|
+
warn: {
|
|
30
|
+
(...data: any[]): void;
|
|
31
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
baseUrl?: string;
|
|
35
|
+
hooks?: {
|
|
36
|
+
beforeRequest?: (config: _descope_core_js_sdk.RequestConfig) => _descope_core_js_sdk.RequestConfig;
|
|
37
|
+
afterRequest?: (req: _descope_core_js_sdk.RequestConfig, res: Response) => void | Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
cookiePolicy?: RequestCredentials;
|
|
40
|
+
baseHeaders?: HeadersInit;
|
|
41
|
+
}, "hooks"> & {
|
|
42
|
+
hooks?: {
|
|
43
|
+
beforeRequest?: ((config: _descope_core_js_sdk.RequestConfig) => _descope_core_js_sdk.RequestConfig) | ((config: _descope_core_js_sdk.RequestConfig) => _descope_core_js_sdk.RequestConfig)[];
|
|
44
|
+
afterRequest?: ((req: _descope_core_js_sdk.RequestConfig, res: Response) => void | Promise<void>) | ((req: _descope_core_js_sdk.RequestConfig, res: Response) => void | Promise<void>)[];
|
|
45
|
+
};
|
|
46
|
+
} & {
|
|
47
|
+
fpKey?: string;
|
|
48
|
+
fpLoad?: boolean;
|
|
49
|
+
} & {
|
|
50
|
+
autoRefresh?: boolean;
|
|
51
|
+
} & {
|
|
52
|
+
persistTokens?: boolean;
|
|
53
|
+
sessionTokenViaCookie?: boolean;
|
|
54
|
+
}>(config: P) => (({
|
|
55
|
+
flow: {
|
|
56
|
+
start: (flowId: string, options?: {
|
|
57
|
+
tenant?: string;
|
|
58
|
+
}, interactionId?: string, input?: {
|
|
59
|
+
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
60
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.FlowResponse>>;
|
|
61
|
+
next: (executionId: string, stepId: string, interactionId: string, input?: {
|
|
62
|
+
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
63
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.FlowResponse>>;
|
|
64
|
+
};
|
|
65
|
+
webauthn: {
|
|
66
|
+
signUp: ((identifier: string, name: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>) & {
|
|
67
|
+
start: (loginId: string, origin: string, name: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
68
|
+
transactionId: string;
|
|
69
|
+
options: string;
|
|
70
|
+
create: boolean;
|
|
71
|
+
}>>;
|
|
72
|
+
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
73
|
+
};
|
|
74
|
+
signIn: ((identifier: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>) & {
|
|
75
|
+
start: (loginId: string, origin: string, loginOptions?: {
|
|
76
|
+
stepup?: boolean;
|
|
77
|
+
mfa?: boolean;
|
|
78
|
+
customClaims?: Record<string, any>;
|
|
79
|
+
}, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
80
|
+
transactionId: string;
|
|
81
|
+
options: string;
|
|
82
|
+
create: boolean;
|
|
83
|
+
}>>;
|
|
84
|
+
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
85
|
+
};
|
|
86
|
+
signUpOrIn: ((identifier: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>) & {
|
|
87
|
+
start: (loginId: string, origin: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
88
|
+
transactionId: string;
|
|
89
|
+
options: string;
|
|
90
|
+
create: boolean;
|
|
91
|
+
}>>;
|
|
92
|
+
};
|
|
93
|
+
update: ((identifier: string, token: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.ResponseData>>) & {
|
|
94
|
+
start: (loginId: string, origin: string, token: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
95
|
+
transactionId: string;
|
|
96
|
+
options: string;
|
|
97
|
+
create: boolean;
|
|
98
|
+
}>>;
|
|
99
|
+
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.ResponseData>>;
|
|
100
|
+
};
|
|
101
|
+
helpers: {
|
|
102
|
+
create: (options: string) => Promise<string>;
|
|
103
|
+
get: (options: string) => Promise<string>;
|
|
104
|
+
isSupported: (requirePlatformAuthenticator?: boolean) => Promise<boolean>;
|
|
105
|
+
conditional: (options: string, abort: AbortController) => Promise<string>;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
accessKey: {
|
|
109
|
+
exchange: (accessKey: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.ExchangeAccessKeyResponse>>;
|
|
110
|
+
};
|
|
111
|
+
otp: {
|
|
112
|
+
verify: {
|
|
113
|
+
email: (loginId: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
114
|
+
sms: (loginId: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
115
|
+
whatsapp: (loginId: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
116
|
+
};
|
|
117
|
+
signIn: {
|
|
118
|
+
email: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
119
|
+
sms: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
120
|
+
whatsapp: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
121
|
+
};
|
|
122
|
+
signUp: {
|
|
123
|
+
email: (loginId: string, user?: {
|
|
124
|
+
email?: string;
|
|
125
|
+
name?: string;
|
|
126
|
+
phone?: string;
|
|
127
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
128
|
+
sms: (loginId: string, user?: {
|
|
129
|
+
email?: string;
|
|
130
|
+
name?: string;
|
|
131
|
+
phone?: string;
|
|
132
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
133
|
+
whatsapp: (loginId: string, user?: {
|
|
134
|
+
email?: string;
|
|
135
|
+
name?: string;
|
|
136
|
+
phone?: string;
|
|
137
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
138
|
+
};
|
|
139
|
+
signUpOrIn: {
|
|
140
|
+
email: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
141
|
+
sms: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
142
|
+
whatsapp: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
143
|
+
};
|
|
144
|
+
update: {
|
|
145
|
+
email: (loginId: string, email: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
146
|
+
phone: {
|
|
147
|
+
email: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
148
|
+
sms: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
149
|
+
whatsapp: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
magicLink: {
|
|
154
|
+
verify: (token: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
155
|
+
signIn: {
|
|
156
|
+
email: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
157
|
+
sms: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
158
|
+
whatsapp: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
159
|
+
};
|
|
160
|
+
signUp: {
|
|
161
|
+
email: (loginId: string, uri: string, user?: {
|
|
162
|
+
email?: string;
|
|
163
|
+
name?: string;
|
|
164
|
+
phone?: string;
|
|
165
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
166
|
+
sms: (loginId: string, uri: string, user?: {
|
|
167
|
+
email?: string;
|
|
168
|
+
name?: string;
|
|
169
|
+
phone?: string;
|
|
170
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
171
|
+
whatsapp: (loginId: string, uri: string, user?: {
|
|
172
|
+
email?: string;
|
|
173
|
+
name?: string;
|
|
174
|
+
phone?: string;
|
|
175
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
176
|
+
};
|
|
177
|
+
signUpOrIn: {
|
|
178
|
+
email: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
179
|
+
sms: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
180
|
+
whatsapp: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
181
|
+
};
|
|
182
|
+
update: {
|
|
183
|
+
email: (loginId: string, email: string, uri: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
184
|
+
phone: {
|
|
185
|
+
email: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
186
|
+
sms: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
187
|
+
whatsapp: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
enchantedLink: {
|
|
192
|
+
verify: (token: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
193
|
+
signIn: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
194
|
+
signUpOrIn: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
195
|
+
signUp: (loginId: string, uri: string, user?: {
|
|
196
|
+
email?: string;
|
|
197
|
+
name?: string;
|
|
198
|
+
phone?: string;
|
|
199
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
200
|
+
waitForSession: (pendingRef: string, config?: {
|
|
201
|
+
pollingIntervalMs: number;
|
|
202
|
+
timeoutMs: number;
|
|
203
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
204
|
+
update: {
|
|
205
|
+
email: (loginId: string, email: string, uri: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
oauth: {
|
|
209
|
+
start: {
|
|
210
|
+
facebook: <B extends {
|
|
211
|
+
redirect: boolean;
|
|
212
|
+
}>(redirectURL?: string, config?: B) => Promise<B extends {
|
|
213
|
+
redirect: true;
|
|
214
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
215
|
+
github: <B_1 extends {
|
|
216
|
+
redirect: boolean;
|
|
217
|
+
}>(redirectURL?: string, config?: B_1) => Promise<B_1 extends {
|
|
218
|
+
redirect: true;
|
|
219
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
220
|
+
google: <B_2 extends {
|
|
221
|
+
redirect: boolean;
|
|
222
|
+
}>(redirectURL?: string, config?: B_2) => Promise<B_2 extends {
|
|
223
|
+
redirect: true;
|
|
224
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
225
|
+
microsoft: <B_3 extends {
|
|
226
|
+
redirect: boolean;
|
|
227
|
+
}>(redirectURL?: string, config?: B_3) => Promise<B_3 extends {
|
|
228
|
+
redirect: true;
|
|
229
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
230
|
+
gitlab: <B_4 extends {
|
|
231
|
+
redirect: boolean;
|
|
232
|
+
}>(redirectURL?: string, config?: B_4) => Promise<B_4 extends {
|
|
233
|
+
redirect: true;
|
|
234
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
235
|
+
apple: <B_5 extends {
|
|
236
|
+
redirect: boolean;
|
|
237
|
+
}>(redirectURL?: string, config?: B_5) => Promise<B_5 extends {
|
|
238
|
+
redirect: true;
|
|
239
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
240
|
+
discord: <B_6 extends {
|
|
241
|
+
redirect: boolean;
|
|
242
|
+
}>(redirectURL?: string, config?: B_6) => Promise<B_6 extends {
|
|
243
|
+
redirect: true;
|
|
244
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
245
|
+
linkedin: <B_7 extends {
|
|
246
|
+
redirect: boolean;
|
|
247
|
+
}>(redirectURL?: string, config?: B_7) => Promise<B_7 extends {
|
|
248
|
+
redirect: true;
|
|
249
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
250
|
+
};
|
|
251
|
+
exchange: (code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
252
|
+
};
|
|
253
|
+
saml: {
|
|
254
|
+
start: <B_1_1 extends {
|
|
255
|
+
redirect: boolean;
|
|
256
|
+
}>(tenantNameOrEmail: string, config?: B_1_1) => Promise<B_1_1 extends {
|
|
257
|
+
redirect: true;
|
|
258
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
259
|
+
exchange: (code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
260
|
+
};
|
|
261
|
+
totp: {
|
|
262
|
+
signUp: (loginId: string, user?: {
|
|
263
|
+
email?: string;
|
|
264
|
+
name?: string;
|
|
265
|
+
phone?: string;
|
|
266
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
|
|
267
|
+
verify: (loginId: string, code: string, loginOptions?: {
|
|
268
|
+
stepup?: boolean;
|
|
269
|
+
mfa?: boolean;
|
|
270
|
+
customClaims?: Record<string, any>;
|
|
271
|
+
}, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
272
|
+
update: (loginId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
|
|
273
|
+
};
|
|
274
|
+
refresh: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
275
|
+
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
276
|
+
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
277
|
+
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
278
|
+
isJwtExpired: (token: string) => boolean;
|
|
279
|
+
getJwtPermissions: (token: string, tenant?: string) => string[];
|
|
280
|
+
getJwtRoles: (token: string, tenant?: string) => string[];
|
|
281
|
+
httpClient: {
|
|
282
|
+
get: (path: string, config?: {
|
|
283
|
+
headers?: HeadersInit;
|
|
284
|
+
queryParams?: {
|
|
285
|
+
[key: string]: string;
|
|
286
|
+
};
|
|
287
|
+
token?: string;
|
|
288
|
+
}) => Promise<Response>;
|
|
289
|
+
post: (path: string, body?: any, config?: {
|
|
290
|
+
headers?: HeadersInit;
|
|
291
|
+
queryParams?: {
|
|
292
|
+
[key: string]: string;
|
|
293
|
+
};
|
|
294
|
+
token?: string;
|
|
295
|
+
}) => Promise<Response>;
|
|
296
|
+
put: (path: string, body?: any, config?: {
|
|
297
|
+
headers?: HeadersInit;
|
|
298
|
+
queryParams?: {
|
|
299
|
+
[key: string]: string;
|
|
300
|
+
};
|
|
301
|
+
token?: string;
|
|
302
|
+
}) => Promise<Response>;
|
|
303
|
+
delete: (path: string, body?: any, config?: {
|
|
304
|
+
headers?: HeadersInit;
|
|
305
|
+
queryParams?: {
|
|
306
|
+
[key: string]: string;
|
|
307
|
+
};
|
|
308
|
+
token?: string;
|
|
309
|
+
}) => Promise<Response>;
|
|
310
|
+
hooks?: {
|
|
311
|
+
beforeRequest?: (config: _descope_core_js_sdk.RequestConfig) => _descope_core_js_sdk.RequestConfig;
|
|
312
|
+
afterRequest?: (req: _descope_core_js_sdk.RequestConfig, res: Response) => void | Promise<void>;
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
} | {
|
|
316
|
+
flow: {
|
|
317
|
+
start: (flowId: string, options?: {
|
|
318
|
+
tenant?: string;
|
|
319
|
+
}, interactionId?: string, input?: {
|
|
320
|
+
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
321
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.FlowResponse>>;
|
|
322
|
+
next: (executionId: string, stepId: string, interactionId: string, input?: {
|
|
323
|
+
[x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any[])[])[])[])[])[])[])[])[])[])[];
|
|
324
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.FlowResponse>>;
|
|
325
|
+
};
|
|
326
|
+
webauthn: {
|
|
327
|
+
signUp: ((identifier: string, name: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>) & {
|
|
328
|
+
start: (loginId: string, origin: string, name: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
329
|
+
transactionId: string;
|
|
330
|
+
options: string;
|
|
331
|
+
create: boolean;
|
|
332
|
+
}>>;
|
|
333
|
+
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
334
|
+
};
|
|
335
|
+
signIn: ((identifier: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>) & {
|
|
336
|
+
start: (loginId: string, origin: string, loginOptions?: {
|
|
337
|
+
stepup?: boolean;
|
|
338
|
+
mfa?: boolean;
|
|
339
|
+
customClaims?: Record<string, any>;
|
|
340
|
+
}, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
341
|
+
transactionId: string;
|
|
342
|
+
options: string;
|
|
343
|
+
create: boolean;
|
|
344
|
+
}>>;
|
|
345
|
+
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
346
|
+
};
|
|
347
|
+
signUpOrIn: ((identifier: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>) & {
|
|
348
|
+
start: (loginId: string, origin: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
349
|
+
transactionId: string;
|
|
350
|
+
options: string;
|
|
351
|
+
create: boolean;
|
|
352
|
+
}>>;
|
|
353
|
+
};
|
|
354
|
+
update: ((identifier: string, token: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.ResponseData>>) & {
|
|
355
|
+
start: (loginId: string, origin: string, token: string) => Promise<_descope_core_js_sdk.SdkResponse<{
|
|
356
|
+
transactionId: string;
|
|
357
|
+
options: string;
|
|
358
|
+
create: boolean;
|
|
359
|
+
}>>;
|
|
360
|
+
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.ResponseData>>;
|
|
361
|
+
};
|
|
362
|
+
helpers: {
|
|
363
|
+
create: (options: string) => Promise<string>;
|
|
364
|
+
get: (options: string) => Promise<string>;
|
|
365
|
+
isSupported: (requirePlatformAuthenticator?: boolean) => Promise<boolean>;
|
|
366
|
+
conditional: (options: string, abort: AbortController) => Promise<string>;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
accessKey: {
|
|
370
|
+
exchange: (accessKey: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.ExchangeAccessKeyResponse>>;
|
|
371
|
+
};
|
|
372
|
+
otp: {
|
|
373
|
+
verify: {
|
|
374
|
+
email: (loginId: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
375
|
+
sms: (loginId: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
376
|
+
whatsapp: (loginId: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
377
|
+
};
|
|
378
|
+
signIn: {
|
|
379
|
+
email: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
380
|
+
sms: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
381
|
+
whatsapp: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
382
|
+
};
|
|
383
|
+
signUp: {
|
|
384
|
+
email: (loginId: string, user?: {
|
|
385
|
+
email?: string;
|
|
386
|
+
name?: string;
|
|
387
|
+
phone?: string;
|
|
388
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
389
|
+
sms: (loginId: string, user?: {
|
|
390
|
+
email?: string;
|
|
391
|
+
name?: string;
|
|
392
|
+
phone?: string;
|
|
393
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
394
|
+
whatsapp: (loginId: string, user?: {
|
|
395
|
+
email?: string;
|
|
396
|
+
name?: string;
|
|
397
|
+
phone?: string;
|
|
398
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
399
|
+
};
|
|
400
|
+
signUpOrIn: {
|
|
401
|
+
email: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
402
|
+
sms: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
403
|
+
whatsapp: (loginId: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
404
|
+
};
|
|
405
|
+
update: {
|
|
406
|
+
email: (loginId: string, email: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
407
|
+
phone: {
|
|
408
|
+
email: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
409
|
+
sms: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
410
|
+
whatsapp: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
magicLink: {
|
|
415
|
+
verify: (token: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
416
|
+
signIn: {
|
|
417
|
+
email: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
418
|
+
sms: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
419
|
+
whatsapp: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
420
|
+
};
|
|
421
|
+
signUp: {
|
|
422
|
+
email: (loginId: string, uri: string, user?: {
|
|
423
|
+
email?: string;
|
|
424
|
+
name?: string;
|
|
425
|
+
phone?: string;
|
|
426
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
427
|
+
sms: (loginId: string, uri: string, user?: {
|
|
428
|
+
email?: string;
|
|
429
|
+
name?: string;
|
|
430
|
+
phone?: string;
|
|
431
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
432
|
+
whatsapp: (loginId: string, uri: string, user?: {
|
|
433
|
+
email?: string;
|
|
434
|
+
name?: string;
|
|
435
|
+
phone?: string;
|
|
436
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
437
|
+
};
|
|
438
|
+
signUpOrIn: {
|
|
439
|
+
email: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
440
|
+
sms: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
441
|
+
whatsapp: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
442
|
+
};
|
|
443
|
+
update: {
|
|
444
|
+
email: (loginId: string, email: string, uri: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
445
|
+
phone: {
|
|
446
|
+
email: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
447
|
+
sms: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
448
|
+
whatsapp: (loginId: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
enchantedLink: {
|
|
453
|
+
verify: (token: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
454
|
+
signIn: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
455
|
+
signUpOrIn: (loginId: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
456
|
+
signUp: (loginId: string, uri: string, user?: {
|
|
457
|
+
email?: string;
|
|
458
|
+
name?: string;
|
|
459
|
+
phone?: string;
|
|
460
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
461
|
+
waitForSession: (pendingRef: string, config?: {
|
|
462
|
+
pollingIntervalMs: number;
|
|
463
|
+
timeoutMs: number;
|
|
464
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
465
|
+
update: {
|
|
466
|
+
email: (loginId: string, email: string, uri: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
oauth: {
|
|
470
|
+
start: {
|
|
471
|
+
facebook: <B_8 extends {
|
|
472
|
+
redirect: boolean;
|
|
473
|
+
}>(redirectURL?: string, config?: B_8) => Promise<B_8 extends {
|
|
474
|
+
redirect: true;
|
|
475
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
476
|
+
github: <B_1_2 extends {
|
|
477
|
+
redirect: boolean;
|
|
478
|
+
}>(redirectURL?: string, config?: B_1_2) => Promise<B_1_2 extends {
|
|
479
|
+
redirect: true;
|
|
480
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
481
|
+
google: <B_2_1 extends {
|
|
482
|
+
redirect: boolean;
|
|
483
|
+
}>(redirectURL?: string, config?: B_2_1) => Promise<B_2_1 extends {
|
|
484
|
+
redirect: true;
|
|
485
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
486
|
+
microsoft: <B_3_1 extends {
|
|
487
|
+
redirect: boolean;
|
|
488
|
+
}>(redirectURL?: string, config?: B_3_1) => Promise<B_3_1 extends {
|
|
489
|
+
redirect: true;
|
|
490
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
491
|
+
gitlab: <B_4_1 extends {
|
|
492
|
+
redirect: boolean;
|
|
493
|
+
}>(redirectURL?: string, config?: B_4_1) => Promise<B_4_1 extends {
|
|
494
|
+
redirect: true;
|
|
495
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
496
|
+
apple: <B_5_1 extends {
|
|
497
|
+
redirect: boolean;
|
|
498
|
+
}>(redirectURL?: string, config?: B_5_1) => Promise<B_5_1 extends {
|
|
499
|
+
redirect: true;
|
|
500
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
501
|
+
discord: <B_6_1 extends {
|
|
502
|
+
redirect: boolean;
|
|
503
|
+
}>(redirectURL?: string, config?: B_6_1) => Promise<B_6_1 extends {
|
|
504
|
+
redirect: true;
|
|
505
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
506
|
+
linkedin: <B_7_1 extends {
|
|
507
|
+
redirect: boolean;
|
|
508
|
+
}>(redirectURL?: string, config?: B_7_1) => Promise<B_7_1 extends {
|
|
509
|
+
redirect: true;
|
|
510
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
511
|
+
};
|
|
512
|
+
exchange: (code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
513
|
+
};
|
|
514
|
+
saml: {
|
|
515
|
+
start: <B_1_3 extends {
|
|
516
|
+
redirect: boolean;
|
|
517
|
+
}>(tenantNameOrEmail: string, config?: B_1_3) => Promise<B_1_3 extends {
|
|
518
|
+
redirect: true;
|
|
519
|
+
} ? undefined : _descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.URLResponse>>;
|
|
520
|
+
exchange: (code: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
521
|
+
};
|
|
522
|
+
totp: {
|
|
523
|
+
signUp: (loginId: string, user?: {
|
|
524
|
+
email?: string;
|
|
525
|
+
name?: string;
|
|
526
|
+
phone?: string;
|
|
527
|
+
}) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
|
|
528
|
+
verify: (loginId: string, code: string, loginOptions?: {
|
|
529
|
+
stepup?: boolean;
|
|
530
|
+
mfa?: boolean;
|
|
531
|
+
customClaims?: Record<string, any>;
|
|
532
|
+
}, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
533
|
+
update: (loginId: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
|
|
534
|
+
};
|
|
535
|
+
refresh: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.JWTResponse>>;
|
|
536
|
+
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
537
|
+
logoutAll: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<never>>;
|
|
538
|
+
me: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.UserResponse>>;
|
|
539
|
+
isJwtExpired: (token: string) => boolean;
|
|
540
|
+
getJwtPermissions: (token: string, tenant?: string) => string[];
|
|
541
|
+
getJwtRoles: (token: string, tenant?: string) => string[];
|
|
542
|
+
httpClient: {
|
|
543
|
+
get: (path: string, config?: {
|
|
544
|
+
headers?: HeadersInit;
|
|
545
|
+
queryParams?: {
|
|
546
|
+
[key: string]: string;
|
|
547
|
+
};
|
|
548
|
+
token?: string;
|
|
549
|
+
}) => Promise<Response>;
|
|
550
|
+
post: (path: string, body?: any, config?: {
|
|
551
|
+
headers?: HeadersInit;
|
|
552
|
+
queryParams?: {
|
|
553
|
+
[key: string]: string;
|
|
554
|
+
};
|
|
555
|
+
token?: string;
|
|
556
|
+
}) => Promise<Response>;
|
|
557
|
+
put: (path: string, body?: any, config?: {
|
|
558
|
+
headers?: HeadersInit;
|
|
559
|
+
queryParams?: {
|
|
560
|
+
[key: string]: string;
|
|
561
|
+
};
|
|
562
|
+
token?: string;
|
|
563
|
+
}) => Promise<Response>;
|
|
564
|
+
delete: (path: string, body?: any, config?: {
|
|
565
|
+
headers?: HeadersInit;
|
|
566
|
+
queryParams?: {
|
|
567
|
+
[key: string]: string;
|
|
568
|
+
};
|
|
569
|
+
token?: string;
|
|
570
|
+
}) => Promise<Response>;
|
|
571
|
+
hooks?: {
|
|
572
|
+
beforeRequest?: (config: _descope_core_js_sdk.RequestConfig) => _descope_core_js_sdk.RequestConfig;
|
|
573
|
+
afterRequest?: (req: _descope_core_js_sdk.RequestConfig, res: Response) => void | Promise<void>;
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
}) & {
|
|
577
|
+
onSessionTokenChange: (cb: (data: string) => void) => () => any[];
|
|
578
|
+
onUserChange: (cb: (data: _descope_core_js_sdk.UserResponse) => void) => () => any[];
|
|
579
|
+
}) & {
|
|
580
|
+
getRefreshToken: () => string;
|
|
581
|
+
getSessionToken: () => string;
|
|
582
|
+
};
|
|
583
|
+
declare const getSessionToken: () => string;
|
|
584
|
+
declare const getJwtPermissions: (token?: any, tenant?: string) => string[];
|
|
585
|
+
declare const getJwtRoles: (token?: any, tenant?: string) => string[];
|
|
586
|
+
declare const getRefreshToken: () => string;
|
|
587
|
+
|
|
12
588
|
declare global {
|
|
13
589
|
namespace JSX {
|
|
14
590
|
interface IntrinsicElements {
|
|
@@ -16,43 +592,30 @@ declare global {
|
|
|
16
592
|
}
|
|
17
593
|
}
|
|
18
594
|
}
|
|
19
|
-
|
|
595
|
+
type Sdk = ReturnType<typeof createSdkWrapper>;
|
|
596
|
+
type CustomEvents<K extends string> = {
|
|
20
597
|
[key in K]: (event: CustomEvent) => void;
|
|
21
598
|
};
|
|
22
|
-
|
|
599
|
+
type CustomElement<T, K extends string = ''> = Partial<T & DOMAttributes<T> & {
|
|
23
600
|
children: React.ReactChild;
|
|
24
601
|
ref: React.Ref<HTMLElement>;
|
|
25
602
|
} & CustomEvents<`on${K}`>>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
invited = "invited",
|
|
31
|
-
unknown = "unknown"
|
|
32
|
-
}
|
|
33
|
-
interface IExternalID {
|
|
34
|
-
id: string;
|
|
35
|
-
type?: string;
|
|
36
|
-
}
|
|
37
|
-
interface User {
|
|
38
|
-
externalIDs?: IExternalID[];
|
|
39
|
-
displayName?: string;
|
|
40
|
-
project?: string;
|
|
41
|
-
logoutTime?: number;
|
|
42
|
-
createTime?: number;
|
|
43
|
-
email?: string;
|
|
44
|
-
phoneNumber?: string;
|
|
45
|
-
status?: UserStatus;
|
|
46
|
-
verifiedEmail?: boolean;
|
|
47
|
-
verifiedPhone?: boolean;
|
|
48
|
-
tenants?: string[];
|
|
603
|
+
type DescopeCustomElement = CustomElement<DescopeWc, 'success' | 'error'>;
|
|
604
|
+
interface IAuth {
|
|
605
|
+
logoutAll: Sdk['logoutAll'];
|
|
606
|
+
logout: Sdk['logout'];
|
|
49
607
|
}
|
|
608
|
+
type DescopeTheme = 'light' | 'dark';
|
|
50
609
|
interface DescopeProps {
|
|
51
610
|
flowId: string;
|
|
52
611
|
onSuccess?: DescopeCustomElement['onsuccess'];
|
|
53
612
|
onError?: DescopeCustomElement['onerror'];
|
|
613
|
+
tenant?: string;
|
|
614
|
+
theme?: DescopeTheme;
|
|
615
|
+
debug?: boolean;
|
|
616
|
+
telemetryKey?: string;
|
|
54
617
|
}
|
|
55
|
-
|
|
618
|
+
type DefaultFlowProps = Omit<DescopeProps, 'flowId'>;
|
|
56
619
|
|
|
57
620
|
declare const SignInFlow: (props: DefaultFlowProps) => JSX.Element;
|
|
58
621
|
declare const SignUpFlow: (props: DefaultFlowProps) => JSX.Element;
|
|
@@ -60,12 +623,17 @@ declare const SignUpOrInFlow: (props: DefaultFlowProps) => JSX.Element;
|
|
|
60
623
|
|
|
61
624
|
declare const Descope: React.ForwardRefExoticComponent<DescopeProps & React.RefAttributes<HTMLElement>>;
|
|
62
625
|
|
|
63
|
-
declare const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
user: User;
|
|
626
|
+
declare const useDescope: () => IAuth;
|
|
627
|
+
|
|
628
|
+
declare const useSession: () => {
|
|
629
|
+
isSessionLoading: boolean;
|
|
68
630
|
sessionToken: string;
|
|
631
|
+
isAuthenticated: boolean;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
declare const useUser: () => {
|
|
635
|
+
isUserLoading: boolean;
|
|
636
|
+
user: _descope_core_js_sdk.UserResponse;
|
|
69
637
|
};
|
|
70
638
|
|
|
71
|
-
export { AuthProvider, Descope, SignInFlow, SignUpFlow, SignUpOrInFlow,
|
|
639
|
+
export { AuthProvider, Descope, SignInFlow, SignUpFlow, SignUpOrInFlow, getJwtPermissions, getJwtRoles, getRefreshToken, getSessionToken, useDescope, useSession, useUser };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e,{useMemo as t,useState as o,useEffect as s,useCallback as r,lazy as n,useImperativeHandle as i,Suspense as c,useContext as a,useRef as l}from"react";import d from"@descope/web-js-sdk";const u=e.createContext(void 0),f={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.52-alpha.82"},p=e=>(...t)=>{if(!e)throw Error("You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component");return e(...t)},h=e=>(...t)=>{let o;try{o=e(...t)}catch(e){console.error(e)}return o};let m;const g=e=>{const t=d({...e,persistTokens:!0,autoRefresh:!0});return m=t,t};m=g({projectId:"temp pid"});const k=()=>m?.getSessionToken(),b=h(((e=k(),t)=>m?.getJwtPermissions(e,t))),w=h(((e=k(),t)=>m?.getJwtRoles(e,t))),v=()=>m?.getRefreshToken();const U=({projectId:n,baseUrl:i,sessionTokenViaCookie:c,children:a})=>{const[l,d]=o(),[h,m]=o(),[k,b]=o(!1),[w,v]=o(!1),U=(({projectId:e,baseUrl:o,sessionTokenViaCookie:s})=>t((()=>{if(e)return g({projectId:e,baseUrl:o,sessionTokenViaCookie:s,baseHeaders:f,persistToken:!0,autoRefresh:!0})}),[e,o,s]))({projectId:n,baseUrl:i,sessionTokenViaCookie:c});s((()=>{if(U){const e=U.onSessionTokenChange(m),t=U.onUserChange(d);return()=>{e(),t()}}}),[U]);const E=r((()=>{v(!0),p(U?.refresh)().then((()=>{v(!1)}))}),[U]),I=r((()=>{b(!0),p(U.me)().then((()=>{b(!1)}))}),[U]),y=r(p(U?.logoutAll),[U]),j=r(p(U?.logout),[U]),C=t((()=>({fetchUser:I,user:l,isUserLoading:k,fetchSession:E,session:h,isSessionLoading:w,logout:j,logoutAll:y,projectId:n,baseUrl:i,setUser:d,setSession:m,sdk:U})),[I,l,k,E,h,w,j,y,n,i,d,m,U]);return e.createElement(u.Provider,{value:C},a)};U.defaultProps={baseUrl:"",children:void 0,sessionTokenViaCookie:!1};const E=n((async()=>((await import("@descope/web-component")).default.sdkConfigOverrides={baseHeaders:f},{default:({projectId:t,flowId:o,baseUrl:s,innerRef:r,tenant:n,theme:i,debug:c,telemetryKey:a})=>e.createElement("descope-wc",{"project-id":t,"flow-id":o,"base-url":s,ref:r,tenant:n,theme:i,debug:c,telemetryKey:a})}))),I=e.forwardRef((({flowId:t,onSuccess:n,onError:a,tenant:l,theme:d,debug:f,telemetryKey:p},h)=>{const[m,g]=o(null);i(h,(()=>m));const{projectId:k,baseUrl:b,setUser:w,setSession:v,sdk:U}=e.useContext(u),I=r((async e=>{w(e.detail?.user);const t=e.detail?.sessionJwt;v(t),await U.httpClient.hooks.afterRequest({},new Response(JSON.stringify(e.detail))),n&&n(e)}),[w,v,n]);return s((()=>{const e=m;return e?.addEventListener("success",I),a&&e?.addEventListener("error",a),()=>{a&&e?.removeEventListener("error",a),e?.removeEventListener("success",I)}}),[m,a,I]),e.createElement("form",null,e.createElement(c,{fallback:null},e.createElement(E,{projectId:k,flowId:t,baseUrl:b,innerRef:g,tenant:l,theme:d,debug:f,telemetryKey:p})))}));I.defaultProps={onError:void 0,onSuccess:void 0};const y=t=>e.createElement(I,{...t,flowId:"sign-in"}),j=t=>e.createElement(I,{...t,flowId:"sign-up"}),C=t=>e.createElement(I,{...t,flowId:"sign-up-or-in"});var S=()=>{const e=a(u);if(!e)throw Error("You can only use this hook in the context of <AuthProvider />");return e};const T=()=>{const{logout:e,logoutAll:o}=S();return t((()=>({logoutAll:o,logout:e})),[o,e])},L=()=>{const{session:e,isSessionLoading:o,fetchSession:r}=S(),n=l(o);return t((()=>{n.current=o}),[o]),t((()=>{e||o||(n.current=!0)}),[r]),s((()=>{e||o||r()}),[r]),{isSessionLoading:n.current,sessionToken:e,isAuthenticated:!!e}},R=()=>{const{user:e,fetchUser:r,isUserLoading:n,session:i}=S(),[c,a]=o(!1),d=l(n),u=t((()=>!e&&!n&&i&&!c),[r,i,c]);return t((()=>{d.current=n}),[n]),t((()=>{u&&(d.current=!0)}),[u]),s((()=>{u&&(a(!0),r())}),[u]),{isUserLoading:d.current,user:e}};export{U as AuthProvider,I as Descope,y as SignInFlow,j as SignUpFlow,C as SignUpOrInFlow,b as getJwtPermissions,w as getJwtRoles,v as getRefreshToken,k as getSessionToken,T as useDescope,L as useSession,R as useUser};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/lib/hooks/Context.ts","../src/lib/constants.ts","../src/lib/utils.ts","../src/lib/sdk.ts","../src/lib/components/AuthProvider/AuthProvider.tsx","../src/lib/components/AuthProvider/useSdk.ts","../src/lib/components/Descope.tsx","../src/lib/components/DefaultFlows.tsx","../src/lib/hooks/useContext.ts","../src/lib/hooks/useDescope.ts","../src/lib/hooks/useSession.ts","../src/lib/hooks/useUser.ts"],"sourcesContent":["import React from 'react';\nimport { IContext } from '../types';\n\nconst Context = React.createContext<IContext>(undefined);\n\nexport default Context;\n","declare const BUILD_VERSION: string;\n\n// eslint-disable-next-line import/prefer-default-export\nexport const baseHeaders = {\n\t'x-descope-sdk-name': 'react',\n\t'x-descope-sdk-version': BUILD_VERSION\n};\n","/**\n * Wrap a function with a validation that it exists\n * @param fn The function to wrap with the validation\n * @throws if function does not exist, an error with the relevant message will be thrown\n */\nexport const withValidation =\n\t<T extends Array<any>, U>(fn: (...args: T) => U) =>\n\t(...args: T): U => {\n\t\tif (!fn) {\n\t\t\tthrow Error(\n\t\t\t\t`You can only use this function after sdk initialization. Make sure to supply 'projectId' to <AuthProvider /> component`\n\t\t\t);\n\t\t}\n\t\treturn fn(...args);\n\t};\n\nexport const wrapInTry =\n\t<T extends Array<any>, U>(fn: (...args: T) => U) =>\n\t(...args: T): U => {\n\t\tlet res: U;\n\t\ttry {\n\t\t\tres = fn(...args);\n\t\t} catch (err) {\n\t\t\tconsole.error(err); // eslint-disable-line no-console\n\t\t}\n\t\treturn res;\n\t};\n","import createSdk from '@descope/web-js-sdk';\nimport { wrapInTry } from './utils';\n\ntype Sdk = ReturnType<typeof createSdkWrapper>;\nlet sdkInstance: Sdk;\n\nconst createSdkWrapper = <P extends Parameters<typeof createSdk>[0]>(\n\tconfig: P\n) => {\n\tconst sdk = createSdk({\n\t\t...config,\n\t\tpersistTokens: true,\n\t\tautoRefresh: true\n\t});\n\tsdkInstance = sdk;\n\n\treturn sdk;\n};\n\n/**\n * We want to make sure the getSessionToken fn is used only when persistTokens is on\n *\n * So we are keeping the SDK init in a single place,\n * and we are creating a temp instance in order to export the getSessionToken\n * even before the SDK was init\n */\nsdkInstance = createSdkWrapper({ projectId: 'temp pid' });\n\nexport const getSessionToken = () => sdkInstance?.getSessionToken();\nexport const getJwtPermissions = wrapInTry(\n\t(token = getSessionToken(), tenant?: string) =>\n\t\tsdkInstance?.getJwtPermissions(token, tenant)\n);\nexport const getJwtRoles = wrapInTry(\n\t(token = getSessionToken(), tenant?: string) =>\n\t\tsdkInstance?.getJwtRoles(token, tenant)\n);\nexport const getRefreshToken = () => sdkInstance?.getRefreshToken();\n\nexport default createSdkWrapper;\n","import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport useSdk from './useSdk';\nimport { withValidation } from '../../utils';\n\ninterface IAuthProviderProps {\n\tprojectId: string;\n\tbaseUrl?: string;\n\t// If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n\t// stored on local storage and can accessed with getSessionToken function\n\t// Use this option if session token will stay small (less than 1k)\n\t// NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n\tsessionTokenViaCookie?: boolean;\n\tchildren?: JSX.Element;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n\tprojectId,\n\tbaseUrl,\n\tsessionTokenViaCookie,\n\tchildren\n}) => {\n\tconst [user, setUser] = useState<User>();\n\tconst [session, setSession] = useState<string>();\n\n\tconst [isUserLoading, setIsUserLoading] = useState(false);\n\tconst [isSessionLoading, setIsSessionLoading] = useState(false);\n\n\tconst sdk = useSdk({ projectId, baseUrl, sessionTokenViaCookie });\n\n\tuseEffect(() => {\n\t\tif (sdk) {\n\t\t\tconst unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n\t\t\tconst unsubscribeUser = sdk.onUserChange(setUser);\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeSessionToken();\n\t\t\t\tunsubscribeUser();\n\t\t\t};\n\t\t}\n\t\treturn undefined;\n\t}, [sdk]);\n\n\tconst fetchSession = useCallback(() => {\n\t\tsetIsSessionLoading(true);\n\t\twithValidation(sdk?.refresh)().then(() => {\n\t\t\tsetIsSessionLoading(false);\n\t\t});\n\t}, [sdk]);\n\n\tconst fetchUser = useCallback(() => {\n\t\tsetIsUserLoading(true);\n\t\twithValidation(sdk.me)().then(() => {\n\t\t\tsetIsUserLoading(false);\n\t\t});\n\t}, [sdk]);\n\n\tconst logoutAll = useCallback(withValidation(sdk?.logoutAll), [sdk]);\n\n\tconst logout = useCallback(withValidation(sdk?.logout), [sdk]);\n\n\tconst value = useMemo<IContext>(\n\t\t() => ({\n\t\t\tfetchUser,\n\t\t\tuser,\n\t\t\tisUserLoading,\n\t\t\tfetchSession,\n\t\t\tsession,\n\t\t\tisSessionLoading,\n\t\t\tlogout,\n\t\t\tlogoutAll,\n\t\t\tprojectId,\n\t\t\tbaseUrl,\n\t\t\tsetUser,\n\t\t\tsetSession,\n\t\t\tsdk\n\t\t}),\n\t\t[\n\t\t\tfetchUser,\n\t\t\tuser,\n\t\t\tisUserLoading,\n\t\t\tfetchSession,\n\t\t\tsession,\n\t\t\tisSessionLoading,\n\t\t\tlogout,\n\t\t\tlogoutAll,\n\t\t\tprojectId,\n\t\t\tbaseUrl,\n\t\t\tsetUser,\n\t\t\tsetSession,\n\t\t\tsdk\n\t\t]\n\t);\n\treturn <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nAuthProvider.defaultProps = {\n\tbaseUrl: '',\n\tchildren: undefined,\n\tsessionTokenViaCookie: false\n};\n\nexport default AuthProvider;\n","import { useMemo } from 'react';\nimport { baseHeaders } from '../../constants';\nimport createSdk from '../../sdk';\n\ntype Config = Pick<\n\tParameters<typeof createSdk>[0],\n\t'projectId' | 'baseUrl' | 'sessionTokenViaCookie'\n>;\n\nexport default ({\n\tprojectId,\n\tbaseUrl,\n\tsessionTokenViaCookie\n}: Config): ReturnType<typeof createSdk> =>\n\tuseMemo(() => {\n\t\tif (!projectId) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn createSdk({\n\t\t\tprojectId,\n\t\t\tbaseUrl,\n\t\t\tsessionTokenViaCookie,\n\t\t\tbaseHeaders,\n\t\t\tpersistToken: true,\n\t\t\tautoRefresh: true\n\t\t});\n\t}, [projectId, baseUrl, sessionTokenViaCookie]);\n","import React, {\n\tlazy,\n\tSuspense,\n\tuseCallback,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseState\n} from 'react';\nimport Context from '../hooks/Context';\nimport { DescopeProps } from '../types';\nimport { baseHeaders } from '../constants';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst DescopeWC = lazy(async () => {\n\tconst module = await import('@descope/web-component');\n\t// we want to override the web-component base headers so we can tell that is was used via the React SDK\n\tmodule.default.sdkConfigOverrides = { baseHeaders };\n\n\treturn {\n\t\tdefault: ({\n\t\t\tprojectId,\n\t\t\tflowId,\n\t\t\tbaseUrl,\n\t\t\tinnerRef,\n\t\t\ttenant,\n\t\t\ttheme,\n\t\t\tdebug,\n\t\t\ttelemetryKey\n\t\t}) => (\n\t\t\t<descope-wc\n\t\t\t\tproject-id={projectId}\n\t\t\t\tflow-id={flowId}\n\t\t\t\tbase-url={baseUrl}\n\t\t\t\tref={innerRef}\n\t\t\t\ttenant={tenant}\n\t\t\t\ttheme={theme}\n\t\t\t\tdebug={debug}\n\t\t\t\ttelemetryKey={telemetryKey}\n\t\t\t/>\n\t\t)\n\t};\n});\n\nconst Descope = React.forwardRef<HTMLElement, DescopeProps>(\n\t({ flowId, onSuccess, onError, tenant, theme, debug, telemetryKey }, ref) => {\n\t\tconst [innerRef, setInnerRef] = useState(null);\n\n\t\tuseImperativeHandle(ref, () => innerRef);\n\n\t\tconst { projectId, baseUrl, setUser, setSession, sdk } =\n\t\t\tReact.useContext(Context);\n\n\t\tconst handleSuccess = useCallback(\n\t\t\tasync (e: CustomEvent) => {\n\t\t\t\tsetUser(e.detail?.user);\n\t\t\t\tconst sessionJwt = e.detail?.sessionJwt;\n\t\t\t\tsetSession(sessionJwt);\n\t\t\t\t// In order to make sure all the after-hooks are running with the success response\n\t\t\t\t// we are generating a fake response with the success data and calling the http client after hook fn with it\n\t\t\t\tawait sdk.httpClient.hooks.afterRequest(\n\t\t\t\t\t{} as any,\n\t\t\t\t\tnew Response(JSON.stringify(e.detail))\n\t\t\t\t);\n\t\t\t\tif (onSuccess) {\n\t\t\t\t\tonSuccess(e);\n\t\t\t\t}\n\t\t\t},\n\t\t\t[setUser, setSession, onSuccess]\n\t\t);\n\n\t\tuseEffect(() => {\n\t\t\tconst ele = innerRef;\n\t\t\tele?.addEventListener('success', handleSuccess);\n\t\t\tif (onError) ele?.addEventListener('error', onError);\n\n\t\t\treturn () => {\n\t\t\t\tif (onError) ele?.removeEventListener('error', onError);\n\n\t\t\t\tele?.removeEventListener('success', handleSuccess);\n\t\t\t};\n\t\t}, [innerRef, onError, handleSuccess]);\n\n\t\treturn (\n\t\t\t/**\n\t\t\t * in order to avoid redundant remounting of the WC, we are wrapping it with a form element\n\t\t\t * this workaround is done in order to support webauthn passkeys\n\t\t\t * it can be removed once this issue will be solved\n\t\t\t * https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2\n\t\t\t */\n\t\t\t<form>\n\t\t\t\t<Suspense fallback={null}>\n\t\t\t\t\t<DescopeWC\n\t\t\t\t\t\tprojectId={projectId}\n\t\t\t\t\t\tflowId={flowId}\n\t\t\t\t\t\tbaseUrl={baseUrl}\n\t\t\t\t\t\tinnerRef={setInnerRef}\n\t\t\t\t\t\ttenant={tenant}\n\t\t\t\t\t\ttheme={theme}\n\t\t\t\t\t\tdebug={debug}\n\t\t\t\t\t\ttelemetryKey={telemetryKey}\n\t\t\t\t\t/>\n\t\t\t\t</Suspense>\n\t\t\t</form>\n\t\t);\n\t}\n);\n\nDescope.defaultProps = {\n\tonError: undefined,\n\tonSuccess: undefined\n};\n\nexport default Descope;\n","import React from 'react';\nimport { DefaultFlowProps } from '../types';\nimport Descope from './Descope';\n\nexport const SignInFlow = (props: DefaultFlowProps) => (\n\t<Descope {...props} flowId=\"sign-in\" />\n);\n\nexport const SignUpFlow = (props: DefaultFlowProps) => (\n\t<Descope {...props} flowId=\"sign-up\" />\n);\n\nexport const SignUpOrInFlow = (props: DefaultFlowProps) => (\n\t<Descope {...props} flowId=\"sign-up-or-in\" />\n);\n","import { useContext } from 'react';\nimport Context from './Context';\n\nexport default () => {\n\tconst ctx = useContext(Context);\n\tif (!ctx) {\n\t\tthrow Error(\n\t\t\t`You can only use this hook in the context of <AuthProvider />`\n\t\t);\n\t}\n\n\treturn ctx;\n};\n","import { useMemo } from 'react';\nimport { IAuth } from '../types';\nimport useContext from './useContext';\n\nconst useDescope = (): IAuth => {\n\tconst { logout, logoutAll } = useContext();\n\n\treturn useMemo(\n\t\t() => ({\n\t\t\tlogoutAll,\n\t\t\tlogout\n\t\t}),\n\t\t[logoutAll, logout]\n\t);\n};\n\nexport default useDescope;\n","import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\n\nconst useSession = () => {\n\tconst { session, isSessionLoading, fetchSession } = useContext();\n\n\t// when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n\t// (and not only when receiving an update from the context)\n\tconst isLoading = useRef(isSessionLoading);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tisLoading.current = isSessionLoading;\n\t}, [isSessionLoading]);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tif (!session && !isSessionLoading) {\n\t\t\tisLoading.current = true;\n\t\t}\n\t}, [fetchSession]);\n\n\tuseEffect(() => {\n\t\tif (!session && !isSessionLoading) {\n\t\t\tfetchSession();\n\t\t}\n\t}, [fetchSession]);\n\n\treturn {\n\t\tisSessionLoading: isLoading.current,\n\t\tsessionToken: session,\n\t\tisAuthenticated: !!session\n\t};\n};\n\nexport default useSession;\n","import { useEffect, useMemo, useRef, useState } from 'react';\nimport useContext from './useContext';\n\nconst useUser = () => {\n\tconst { user, fetchUser, isUserLoading, session } = useContext();\n\tconst [isInit, setIsInit] = useState(false); // we want to get the user only in the first time we got a session\n\n\t// when session should be received, we want the return value of \"isUserLoading\" to be true starting from the first call\n\t// (and not only when receiving an update from the context)\n\tconst isLoading = useRef(isUserLoading);\n\n\tconst shouldFetchUser = useMemo(\n\t\t() => !user && !isUserLoading && session && !isInit,\n\t\t[fetchUser, session, isInit]\n\t);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tisLoading.current = isUserLoading;\n\t}, [isUserLoading]);\n\n\t// we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n\tuseMemo(() => {\n\t\tif (shouldFetchUser) {\n\t\t\tisLoading.current = true;\n\t\t}\n\t}, [shouldFetchUser]);\n\n\tuseEffect(() => {\n\t\tif (shouldFetchUser) {\n\t\t\tsetIsInit(true);\n\t\t\tfetchUser();\n\t\t}\n\t}, [shouldFetchUser]);\n\n\treturn { isUserLoading: isLoading.current, user };\n};\n\nexport default useUser;\n"],"names":["Context","React","createContext","undefined","baseHeaders","withValidation","fn","args","Error","wrapInTry","res","err","console","error","sdkInstance","createSdkWrapper","config","sdk","createSdk","persistTokens","autoRefresh","projectId","getSessionToken","getJwtPermissions","token","tenant","getJwtRoles","getRefreshToken","AuthProvider","baseUrl","sessionTokenViaCookie","children","user","setUser","useState","session","setSession","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","useMemo","persistToken","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","fetchSession","useCallback","refresh","then","fetchUser","me","logoutAll","logout","value","createElement","Provider","defaultProps","DescopeWC","lazy","async","import","default","sdkConfigOverrides","flowId","innerRef","theme","debug","telemetryKey","ref","Descope","forwardRef","onSuccess","onError","setInnerRef","useImperativeHandle","useContext","handleSuccess","e","detail","sessionJwt","httpClient","hooks","afterRequest","Response","JSON","stringify","ele","addEventListener","removeEventListener","Suspense","fallback","SignInFlow","props","SignUpFlow","SignUpOrInFlow","ctx","useDescope","useSession","isLoading","useRef","current","sessionToken","isAuthenticated","useUser","isInit","setIsInit","shouldFetchUser"],"mappings":"iMA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|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
2
|
+
"name": "@descope/react-sdk",
|
|
3
|
+
"version": "0.0.52-alpha.82",
|
|
4
|
+
"description": "Descope React SDK",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/descope/react-sdk.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
"require": "./dist/cjs/index.cjs.js",
|
|
13
|
+
"import": "./dist/index.esm.js"
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/cjs/index.cjs.js",
|
|
16
|
+
"module": "dist/index.esm.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rollup -c",
|
|
23
|
+
"format": "prettier . -w --ignore-path .gitignore",
|
|
24
|
+
"format-check": "prettier . --check --ignore-path .gitignore",
|
|
25
|
+
"format-lint": "pretty-quick --staged --ignore-path .gitignore && lint-staged",
|
|
26
|
+
"leaks": "bash ./scripts/gitleaks/gitleaks.sh",
|
|
27
|
+
"lint": "eslint '+(src|test|testUtils)/**/*.+(ts|tsx)' --fix",
|
|
28
|
+
"prepare": "husky install",
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"start": "npm run build && rollup -c rollup.config.app.js -w",
|
|
31
|
+
"test": "jest"
|
|
32
|
+
},
|
|
33
|
+
"lint-staged": {
|
|
34
|
+
"+(src|test|examples)/**/*.{js,ts,jsx,tsx}": [
|
|
35
|
+
"npm run lint"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@descope/web-component": "0.1.0-alpha.42",
|
|
40
|
+
"react-router-dom": "6.8.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@babel/core": "7.20.12",
|
|
44
|
+
"@babel/preset-env": "7.20.2",
|
|
45
|
+
"@babel/preset-react": "7.18.6",
|
|
46
|
+
"@babel/preset-typescript": "7.18.6",
|
|
47
|
+
"@open-wc/rollup-plugin-html": "^1.2.5",
|
|
48
|
+
"@rollup/plugin-commonjs": "^24.0.0",
|
|
49
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
50
|
+
"@rollup/plugin-replace": "^5.0.0",
|
|
51
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
52
|
+
"@testing-library/jest-dom": "5.16.5",
|
|
53
|
+
"@testing-library/react": "13.4.0",
|
|
54
|
+
"@testing-library/user-event": "14.4.3",
|
|
55
|
+
"@types/jest": "^27.0.2",
|
|
56
|
+
"@types/react": "18.0.27",
|
|
57
|
+
"@types/react-dom": "18.0.10",
|
|
58
|
+
"@types/react-router-dom": "^5.3.3",
|
|
59
|
+
"babel-jest": "27.5.1",
|
|
60
|
+
"eslint": "8.33.0",
|
|
61
|
+
"eslint-config-airbnb": "19.0.4",
|
|
62
|
+
"eslint-config-airbnb-typescript": "17.0.0",
|
|
63
|
+
"eslint-config-prettier": "8.6.0",
|
|
64
|
+
"eslint-config-standard": "17.0.0",
|
|
65
|
+
"eslint-import-resolver-typescript": "2.7.1",
|
|
66
|
+
"eslint-plugin-import": "2.27.5",
|
|
67
|
+
"eslint-plugin-jest": "27.2.1",
|
|
68
|
+
"eslint-plugin-jest-dom": "4.0.3",
|
|
69
|
+
"eslint-plugin-jest-formatting": "3.1.0",
|
|
70
|
+
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
71
|
+
"eslint-plugin-n": "15.6.1",
|
|
72
|
+
"eslint-plugin-no-only-tests": "3.1.0",
|
|
73
|
+
"eslint-plugin-prefer-arrow": "1.2.3",
|
|
74
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
75
|
+
"eslint-plugin-promise": "6.1.1",
|
|
76
|
+
"eslint-plugin-react": "7.32.2",
|
|
77
|
+
"eslint-plugin-react-hooks": "4.6.0",
|
|
78
|
+
"eslint-plugin-testing-library": "5.10.0",
|
|
79
|
+
"husky": "^8.0.1",
|
|
80
|
+
"jest": "^27.3.1",
|
|
81
|
+
"jest-extended": "^3.2.2",
|
|
82
|
+
"lint-staged": "^13.0.3",
|
|
83
|
+
"pretty-quick": "^3.1.3",
|
|
84
|
+
"react": "18.2.0",
|
|
85
|
+
"react-dom": "18.2.0",
|
|
86
|
+
"rollup": "^2.62.0",
|
|
87
|
+
"rollup-plugin-auto-external": "^2.0.0",
|
|
88
|
+
"rollup-plugin-browsersync": "^1.3.3",
|
|
89
|
+
"rollup-plugin-define": "^1.0.1",
|
|
90
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
91
|
+
"rollup-plugin-dotenv": "^0.4.1",
|
|
92
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
93
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
94
|
+
"rollup-plugin-serve": "^2.0.0",
|
|
95
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
96
|
+
"ts-jest": "^27.0.7",
|
|
97
|
+
"ts-node": "10.9.1",
|
|
98
|
+
"typescript": "^4.5.3"
|
|
99
|
+
},
|
|
100
|
+
"peerDependencies": {
|
|
101
|
+
"@descope/web-js-sdk": "0.1.0-alpha.29",
|
|
102
|
+
"@types/react": ">=16",
|
|
103
|
+
"react": ">=16"
|
|
104
|
+
}
|
|
80
105
|
}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|