dauth-context-react 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,160 +1,67 @@
1
- # TSDX React User Guide
2
-
3
- Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
4
-
5
- > This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
6
-
7
- > If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
8
-
9
- ## Commands
10
-
11
- TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
12
-
13
- The recommended workflow is to run TSDX in one terminal:
1
+ # Dauth React Context
2
+ This is a simple example of how to use a custom `DauthProvider`, and how to utilize the `Dauth` authentication context in your React application.
14
3
 
4
+ ## Installation
5
+ You can install this package via npm. Make sure you have Node.js installed on your machine. Then, in your project directory, run the following command:
15
6
  ```bash
16
- npm start # or yarn start
7
+ npm install dauth-react-context
17
8
  ```
18
9
 
19
- This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20
-
21
- Then run the example inside another:
22
-
23
- ```bash
24
- cd example
25
- npm i # or yarn to install dependencies
26
- npm start # or yarn start
10
+ ## Code Example
11
+ Here's a simplified example of how to use Dauth Provider:
27
12
  ```
28
-
29
- The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
30
-
31
- To do a one-off build, use `npm run build` or `yarn build`.
32
-
33
- To run tests, use `npm test` or `yarn test`.
34
-
35
- ## Configuration
36
-
37
- Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
38
-
39
- ### Jest
40
-
41
- Jest tests are set up to run with `npm test` or `yarn test`.
42
-
43
- ### Bundle analysis
44
-
45
- Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.
46
-
47
- #### Setup Files
48
-
49
- This is the folder structure we set up for you:
50
-
51
- ```txt
52
- /example
53
- index.html
54
- index.tsx # test your component here in a demo app
55
- package.json
56
- tsconfig.json
57
- /src
58
- index.tsx # EDIT THIS
59
- /test
60
- blah.test.tsx # EDIT THIS
61
- .gitignore
62
- package.json
63
- README.md # EDIT THIS
64
- tsconfig.json
13
+ import React from 'react';
14
+ import ReactDOM from 'react-dom';
15
+ import { RouterProvider } from 'react-router-dom';
16
+ import router from './router/router';
17
+ import { DauthProvider } from 'dauth-react-context';
18
+
19
+ ReactDOM.render(
20
+ <React.StrictMode>
21
+ <DauthProvider
22
+ domainName={domainName}
23
+ sid={sid}
24
+ ssid={ssid}
25
+ >
26
+ <RouterProvider
27
+ router={router}
28
+ fallbackElement={<></>}
29
+ />
30
+ </DauthProvider>
31
+ </React.StrictMode>,
32
+ document.getElementById('root')
33
+ );
65
34
  ```
66
35
 
67
- #### React Testing Library
68
-
69
- We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
70
-
71
- ### Rollup
72
-
73
- TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
74
-
75
- ### TypeScript
76
-
77
- `tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
78
-
79
- ## Continuous Integration
80
-
81
- ### GitHub Actions
82
-
83
- Two actions are added by default:
84
-
85
- - `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
86
- - `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
87
-
88
- ## Optimizations
89
-
90
- Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
91
-
92
- ```js
93
- // ./types/index.d.ts
94
- declare var __DEV__: boolean;
95
-
96
- // inside your code...
97
- if (__DEV__) {
98
- console.log('foo');
99
- }
36
+ ## Example: Using Authentication Context
37
+ Here's an example of how to use the authentication context (dauth-react-context) in your components:
100
38
  ```
39
+ import React, { useContext } from 'react';
40
+ import { DauthContext } from 'dauth-react-context';
41
+
42
+ function SomeComponent() {
43
+ const { isAuthenticated, isLoading, user, loginWithRedirect, logout, getAccessToken } = useContext(DauthContext);
44
+
45
+ return (
46
+ isLoading ? <div>Loading...</div> :
47
+ isAuthenticated ? (
48
+ <div>
49
+ Hello {user.name}
50
+ <button onClick={() => logout()}>Logout</button>
51
+ </div>
52
+ ) : (
53
+ <div>
54
+ <button onClick={() => loginWithRedirect()}>Login</button>
55
+ </div>
56
+ )
57
+ );
58
+ }
101
59
 
102
- You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
103
-
104
- ## Module Formats
105
-
106
- CJS, ESModules, and UMD module formats are supported.
107
-
108
- The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
109
-
110
- ## Deploying the Example Playground
111
-
112
- The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
113
-
114
- ```bash
115
- cd example # if not already in the example folder
116
- npm run build # builds to dist
117
- netlify deploy # deploy the dist folder
118
- ```
119
-
120
- Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
121
-
122
- ```bash
123
- netlify init
124
- # build command: yarn build && cd example && yarn && yarn build
125
- # directory to deploy: example/dist
126
- # pick yes for netlify.toml
60
+ export default SomeComponent;
127
61
  ```
128
62
 
129
- ## Named Exports
130
-
131
- Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
132
-
133
- ## Including Styles
134
-
135
- There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
136
-
137
- For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
138
-
139
- ## Publishing to NPM
140
-
141
- We recommend using [np](https://github.com/sindresorhus/np).
142
-
143
- ## Usage with Lerna
144
-
145
- When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
146
-
147
- The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
148
-
149
- Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
150
-
151
- ```diff
152
- "alias": {
153
- - "react": "../node_modules/react",
154
- - "react-dom": "../node_modules/react-dom"
155
- + "react": "../../../node_modules/react",
156
- + "react-dom": "../../../node_modules/react-dom"
157
- },
158
- ```
63
+ ## About
64
+ This project is maintained by David T. Pizarro Frick.
159
65
 
160
- An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)
66
+ ## License
67
+ This project is licensed under the MIT License.
@@ -385,9 +385,9 @@ function userReducer(state, action) {
385
385
  }
386
386
  }
387
387
 
388
- var isLocalhost = /*#__PURE__*/Boolean(window.location.hostname === "localhost" || window.location.hostname === "[::1]" || /*#__PURE__*/window.location.hostname.match(/(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm) || /*#__PURE__*/window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
389
- var apiVersion = "v1";
390
- var serverDomain = "dauth.ovh";
388
+ var isLocalhost = /*#__PURE__*/Boolean(window.location.hostname === 'localhost' || window.location.hostname === '[::1]' || /*#__PURE__*/window.location.hostname.match(/(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm) || /*#__PURE__*/window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
389
+ var apiVersion = 'v1';
390
+ var serverDomain = 'dauth.ovh';
391
391
  function getServerBasePath(_ref) {
392
392
  var domainName = _ref.domainName;
393
393
  var serverPort = 4012;
@@ -412,10 +412,10 @@ var getTenantUserAPI = /*#__PURE__*/function () {
412
412
  while (1) switch (_context.prev = _context.next) {
413
413
  case 0:
414
414
  params = {
415
- method: "GET",
415
+ method: 'GET',
416
416
  headers: {
417
417
  Authorization: "" + token,
418
- "Content-Type": "application/json"
418
+ 'Content-Type': 'application/json'
419
419
  }
420
420
  };
421
421
  _context.next = 3;
@@ -1 +1 @@
1
- {"version":3,"file":"dauth-context-react.cjs.development.js","sources":["../src/initialDauthState.ts","../src/reducer/dauth.types.ts","../src/reducer/dauth.reducer.ts","../src/api/utils/config.ts","../src/api/dauth.api.ts","../src/constants.ts","../src/reducer/dauth.actions.ts","../src/index.tsx"],"sourcesContent":["export interface IDauthUser {\n\t_id: string\n\tssid: string\n\tname: string\n\tlastname: string\n\tnickname: string\n\temail: string\n\tis_verified: boolean\n\tlanguage: string\n\tavatar: string\n\tcreatedAt: Date\n\tupdatedAt: Date\n\tlast_login: Date\n}\n\nexport interface IDauthDomain {\n\tname: string\n\tloginRedirect: string\n\tallowedOrigins: string[]\n}\n\nexport interface IDauthState {\n\tuser: IDauthUser\n\tdomain: IDauthDomain\n\tisLoading: boolean\n\tisAuthenticated: boolean\n\tloginWithRedirect: () => void\n\tlogout: () => void\n\tgetAccessToken: () => void\n}\n\nconst initialDauthState: IDauthState = {\n\tuser: {} as IDauthUser,\n\tdomain: {} as IDauthDomain,\n\tisLoading: true,\n\tisAuthenticated: false,\n\tloginWithRedirect: () => { },\n\tlogout: () => { },\n\tgetAccessToken: () => { },\n}\n\nexport default initialDauthState","export const LOGIN = 'LOGIN';\nexport const SET_IS_LOADING = 'SET_IS_LOADING';","import * as DauthTypes from './dauth.types'\n\nexport default function userReducer(state: any, action: any) {\n\tconst { type, payload } = action;\n\n\tswitch (type) {\n\t\tcase DauthTypes.LOGIN:\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tuser: payload.user,\n\t\t\t\tdomain: payload.domain,\n\t\t\t\tisAuthenticated: payload.isAuthenticated,\n\t\t\t}\n\n\t\tcase DauthTypes.SET_IS_LOADING:\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tisLoading: payload.isLoading,\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn state\n\t}\n}","const isLocalhost = Boolean(\n window.location.hostname === \"localhost\" ||\n window.location.hostname === \"[::1]\" ||\n window.location.hostname.match(\n /(192)\\.(168)\\.(1)\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm\n ) ||\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\nexport const apiVersion = \"v1\";\nexport const serverDomain = \"dauth.ovh\";\n\nexport function getServerBasePath({ domainName }: { domainName: string }) {\n const serverPort = 4012;\n const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`\n const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`\n const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;\n return serverBasePath;\n}\n\nexport function getClientBasePath({ domainName }: { domainName: string }) {\n const clientPort = 5185;\n const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`\n const clientProdUrl = `https://${domainName}.${serverDomain}`\n const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;\n return clientBasePath;\n}","import { getServerBasePath } from \"./utils/config\";\n\nexport const getTenantUserAPI = async (domainName: string, ssid: string, token: string): Promise<any> => {\n const params = {\n method: \"GET\",\n headers: {\n Authorization: `${token}`,\n \"Content-Type\": \"application/json\",\n }\n }\n const response = await fetch(`${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`, params)\n const data = await response.json()\n return { response, data }\n}","export const DAUTH_STATE = 'dauth_state';","import { getTenantUserAPI } from '../api/dauth.api';\nimport { DAUTH_STATE } from '../constants';\nimport * as DauthTypes from './dauth.types'\n\ntype TSetDauthStateAction = {\n dispatch: any\n dauth_state: string\n domainName: string\n ssid: string\n}\nexport async function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: TSetDauthStateAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n })\n window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);\n return localStorage.setItem(DAUTH_STATE, dauth_state);\n } else {\n return localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n }\n}\n\ntype TSetAutoLoginAction = {\n dispatch: any\n dauth_state_ls: string\n domainName: string\n ssid: string\n}\nexport async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: TSetAutoLoginAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state_ls);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n })\n localStorage.setItem(DAUTH_STATE, dauth_state_ls);\n } else {\n localStorage.removeItem(DAUTH_STATE);\n }\n\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n }\n}\n\nexport async function setLogoutAction({ dispatch }: { dispatch: any }) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: {},\n domain: {},\n isAuthenticated: false,\n },\n })\n localStorage.removeItem(DAUTH_STATE);\n return dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n}","import React, { useReducer, useMemo, useEffect, useCallback, createContext, useContext } from 'react'\nimport initialDauthState, { IDauthState } from './initialDauthState'\nimport userReducer from './reducer/dauth.reducer'\nimport * as action from \"./reducer/dauth.actions\"\nimport { getClientBasePath } from './api/utils/config'\nimport { DAUTH_STATE } from './constants'\n\ninterface DauthProviderProps {\n domainName: string\n sid: string\n ssid: string\n children: React.ReactNode\n}\n\nexport const DauthProvider: React.FC<DauthProviderProps> = (props: DauthProviderProps) => {\n\tconst { domainName, sid, ssid, children } = props\n\tconst [ds, dispatch] = useReducer(userReducer, initialDauthState)\n const dauthState = ds as IDauthState\n\n\t// Catch login redirect\n\tuseEffect(() => {\n\t\tconst queryString = window.location.search;\n\t\tif (!queryString) return\n\t\tconst urlParams = new URLSearchParams(queryString);\n\t\tconst dauth_state = urlParams.get(DAUTH_STATE);\n\t\tif (dauth_state && !dauthState.isAuthenticated) {\n\t\t\taction.setDauthStateAction({ dispatch, dauth_state, domainName, ssid })\n\t\t}\n\t}, [dauthState.isAuthenticated, domainName, ssid])\n\n\t// Auto Login\n\tuseEffect(() => {\n\t\tconst dauth_state_ls = localStorage.getItem(DAUTH_STATE);\n\t\tif (dauth_state_ls && !dauthState.isAuthenticated) {\n\t\t\taction.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid })\n\t\t}\n\t}, [dauthState.isAuthenticated, domainName, ssid])\n\n\tconst loginWithRedirect = useCallback(() => {\n\t\treturn window.location.replace(`${getClientBasePath({ domainName })}/t-sign/${sid}`);\n\t}, [domainName, sid])\n\n\tconst logout = useCallback(() => {\n\t\treturn action.setLogoutAction({ dispatch })\n\t}, [])\n\n\tconst memoProvider = useMemo(\n\t\t() => ({\n\t\t\t...dauthState,\n\t\t\tloginWithRedirect,\n\t\t\tlogout\n\t\t}), [\n\t\tdauthState,\n\t\tloginWithRedirect,\n\t\tlogout\n\t])\n\n\n\treturn (\n\t\t<DauthContext.Provider value={memoProvider}>\n\t\t\t{children}\n\t\t</DauthContext.Provider>\n\t)\n}\n\nconst DauthContext = createContext(initialDauthState);\n\nexport const useDauth = () => {\n const context = useContext(DauthContext);\n if (!context) {\n throw new Error('useMyContext debe ser utilizado dentro de un MyContextProvider');\n }\n return context;\n};"],"names":["initialDauthState","user","domain","isLoading","isAuthenticated","loginWithRedirect","logout","getAccessToken","LOGIN","SET_IS_LOADING","userReducer","state","action","type","payload","DauthTypes","_extends","isLocalhost","Boolean","window","location","hostname","match","apiVersion","serverDomain","getServerBasePath","_ref","domainName","serverPort","serverLocalUrl","protocol","serverProdUrl","serverBasePath","getClientBasePath","_ref2","clientPort","clientLocalUrl","clientProdUrl","clientBasePath","getTenantUserAPI","_asyncToGenerator","_regeneratorRuntime","mark","_callee","ssid","token","params","response","data","wrap","_callee$","_context","prev","next","method","headers","Authorization","fetch","sent","json","abrupt","stop","_x","_x2","_x3","apply","arguments","DAUTH_STATE","setDauthStateAction","_setDauthStateAction","dispatch","dauth_state","getUserFetch","status","history","replaceState","document","title","loginRedirect","localStorage","setItem","removeItem","t0","console","log","finish","setAutoLoginAction","_setAutoLoginAction","_callee2","dauth_state_ls","_callee2$","_context2","setLogoutAction","_setLogoutAction","_callee3","_ref3","_callee3$","_context3","DauthProvider","props","sid","children","_useReducer","useReducer","ds","dauthState","useEffect","queryString","search","urlParams","URLSearchParams","get","getItem","useCallback","replace","memoProvider","useMemo","React","DauthContext","Provider","value","createContext","useDauth","context","useContext","Error"],"mappings":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IAACC,KAAK,EAAEL;KAC5Bd,QAAQ,CACc;AAE1B,CAAC;AAED,IAAMiB,YAAY,gBAAGG,mBAAa,CAACzH,iBAAiB,CAAC;AAErD,IAAa0H,QAAQ,GAAG,SAAXA,QAAQA;EACnB,IAAMC,OAAO,GAAGC,gBAAU,CAACN,YAAY,CAAC;EACxC,IAAI,CAACK,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CAAC,gEAAgE,CAAC;;EAEnF,OAAOF,OAAO;AAChB,CAAC;;;;;"}
1
+ {"version":3,"file":"dauth-context-react.cjs.development.js","sources":["../src/initialDauthState.ts","../src/reducer/dauth.types.ts","../src/reducer/dauth.reducer.ts","../src/api/utils/config.ts","../src/api/dauth.api.ts","../src/constants.ts","../src/reducer/dauth.actions.ts","../src/index.tsx"],"sourcesContent":["export interface IDauthUser {\n _id: string;\n ssid: string;\n name: string;\n lastname: string;\n nickname: string;\n email: string;\n is_verified: boolean;\n language: string;\n avatar: string;\n createdAt: Date;\n updatedAt: Date;\n last_login: Date;\n}\n\nexport interface IDauthDomain {\n name: string;\n loginRedirect: string;\n allowedOrigins: string[];\n}\n\nexport interface IDauthState {\n user: IDauthUser;\n domain: IDauthDomain;\n isLoading: boolean;\n isAuthenticated: boolean;\n loginWithRedirect: () => void;\n logout: () => void;\n getAccessToken: () => void;\n}\n\nconst initialDauthState: IDauthState = {\n user: {} as IDauthUser,\n domain: {} as IDauthDomain,\n isLoading: true,\n isAuthenticated: false,\n loginWithRedirect: () => {},\n logout: () => {},\n getAccessToken: () => {},\n};\n\nexport default initialDauthState;\n","export const LOGIN = 'LOGIN';\nexport const SET_IS_LOADING = 'SET_IS_LOADING';\n","import * as DauthTypes from './dauth.types';\n\nexport default function userReducer(state: any, action: any) {\n const { type, payload } = action;\n\n switch (type) {\n case DauthTypes.LOGIN:\n return {\n ...state,\n user: payload.user,\n domain: payload.domain,\n isAuthenticated: payload.isAuthenticated,\n };\n\n case DauthTypes.SET_IS_LOADING:\n return {\n ...state,\n isLoading: payload.isLoading,\n };\n\n default:\n return state;\n }\n}\n","const isLocalhost = Boolean(\n window.location.hostname === 'localhost' ||\n window.location.hostname === '[::1]' ||\n window.location.hostname.match(\n /(192)\\.(168)\\.(1)\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm\n ) ||\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\nexport const apiVersion = 'v1';\nexport const serverDomain = 'dauth.ovh';\n\nexport function getServerBasePath({ domainName }: { domainName: string }) {\n const serverPort = 4012;\n const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;\n const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`;\n const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;\n return serverBasePath;\n}\n\nexport function getClientBasePath({ domainName }: { domainName: string }) {\n const clientPort = 5185;\n const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;\n const clientProdUrl = `https://${domainName}.${serverDomain}`;\n const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;\n return clientBasePath;\n}\n","import { getServerBasePath } from './utils/config';\n\nexport const getTenantUserAPI = async (\n domainName: string,\n ssid: string,\n token: string\n): Promise<any> => {\n const params = {\n method: 'GET',\n headers: {\n Authorization: `${token}`,\n 'Content-Type': 'application/json',\n },\n };\n const response = await fetch(\n `${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`,\n params\n );\n const data = await response.json();\n return { response, data };\n};\n","export const DAUTH_STATE = 'dauth_state';\n","import { getTenantUserAPI } from '../api/dauth.api';\nimport { DAUTH_STATE } from '../constants';\nimport * as DauthTypes from './dauth.types';\n\ntype TSetDauthStateAction = {\n dispatch: any;\n dauth_state: string;\n domainName: string;\n ssid: string;\n};\nexport async function setDauthStateAction({\n dispatch,\n dauth_state,\n domainName,\n ssid,\n}: TSetDauthStateAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n });\n window.history.replaceState(\n {},\n document.title,\n getUserFetch.data.domain.loginRedirect\n );\n return localStorage.setItem(DAUTH_STATE, dauth_state);\n } else {\n return localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n }\n}\n\ntype TSetAutoLoginAction = {\n dispatch: any;\n dauth_state_ls: string;\n domainName: string;\n ssid: string;\n};\nexport async function setAutoLoginAction({\n dispatch,\n dauth_state_ls,\n domainName,\n ssid,\n}: TSetAutoLoginAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n try {\n const getUserFetch = await getTenantUserAPI(\n domainName,\n ssid,\n dauth_state_ls\n );\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n });\n localStorage.setItem(DAUTH_STATE, dauth_state_ls);\n } else {\n localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n }\n}\n\nexport async function setLogoutAction({ dispatch }: { dispatch: any }) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: {},\n domain: {},\n isAuthenticated: false,\n },\n });\n localStorage.removeItem(DAUTH_STATE);\n return dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n}\n","import React, {\n useReducer,\n useMemo,\n useEffect,\n useCallback,\n createContext,\n useContext,\n} from 'react';\nimport initialDauthState, { IDauthState } from './initialDauthState';\nimport userReducer from './reducer/dauth.reducer';\nimport * as action from './reducer/dauth.actions';\nimport { getClientBasePath } from './api/utils/config';\nimport { DAUTH_STATE } from './constants';\n\ninterface DauthProviderProps {\n domainName: string;\n sid: string;\n ssid: string;\n children: React.ReactNode;\n}\n\nexport const DauthProvider: React.FC<DauthProviderProps> = (\n props: DauthProviderProps\n) => {\n const { domainName, sid, ssid, children } = props;\n const [ds, dispatch] = useReducer(userReducer, initialDauthState);\n const dauthState = ds as IDauthState;\n\n // Catch login redirect\n useEffect(() => {\n const queryString = window.location.search;\n if (!queryString) return;\n const urlParams = new URLSearchParams(queryString);\n const dauth_state = urlParams.get(DAUTH_STATE);\n if (dauth_state && !dauthState.isAuthenticated) {\n action.setDauthStateAction({ dispatch, dauth_state, domainName, ssid });\n }\n }, [dauthState.isAuthenticated, domainName, ssid]);\n\n // Auto Login\n useEffect(() => {\n const dauth_state_ls = localStorage.getItem(DAUTH_STATE);\n if (dauth_state_ls && !dauthState.isAuthenticated) {\n action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid });\n }\n }, [dauthState.isAuthenticated, domainName, ssid]);\n\n const loginWithRedirect = useCallback(() => {\n return window.location.replace(\n `${getClientBasePath({ domainName })}/t-sign/${sid}`\n );\n }, [domainName, sid]);\n\n const logout = useCallback(() => {\n return action.setLogoutAction({ dispatch });\n }, []);\n\n const memoProvider = useMemo(\n () => ({\n ...dauthState,\n loginWithRedirect,\n logout,\n }),\n [dauthState, loginWithRedirect, logout]\n );\n\n return (\n <DauthContext.Provider value={memoProvider}>\n {children}\n </DauthContext.Provider>\n );\n};\n\nconst DauthContext = createContext(initialDauthState);\n\nexport const useDauth = () => {\n const context = useContext(DauthContext);\n if (!context) {\n throw new Error(\n 'useMyContext debe ser utilizado dentro de un MyContextProvider'\n );\n }\n return context;\n};\n"],"names":["initialDauthState","user","domain","isLoading","isAuthenticated","loginWithRedirect","logout","getAccessToken","LOGIN","SET_IS_LOADING","userReducer","state","action","type","payload","DauthTypes","_extends","isLocalhost","Boolean","window","location","hostname","match","apiVersion","serverDomain","getServerBasePath","_ref","domainName","serverPort","serverLocalUrl","protocol","serverProdUrl","serverBasePath","getClientBasePath","_ref2","clientPort","clientLocalUrl","clientProdUrl","clientBasePath","getTenantUserAPI","_asyncToGenerator","_regeneratorRuntime","mark","_callee","ssid","token","params","response","data","wrap","_callee$","_context","prev","next","method","headers","Authorization","fetch","sent","json","abrupt","stop","_x","_x2","_x3","apply","arguments","DAUTH_STATE","setDauthStateAction","_setDauthStateAction","dispatch","dauth_state","getUserFetch","status","history","replaceState","document","title","loginRedirect","localStorage","setItem","removeItem","t0","console","log","finish","setAutoLoginAction","_setAutoLoginAction","_callee2","dauth_state_ls","_callee2$","_context2","setLogoutAction","_setLogoutAction","_callee3","_ref3","_callee3$","_context3","DauthProvider","props","sid","children","_useReducer","useReducer","ds","dauthState","useEffect","queryString","search","urlParams","URLSearchParams","get","getItem","useCallback","replace","memoProvider","useMemo","React","DauthContext","Provider","value","createContext","useDauth","context","useContext","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAMA,iBAAiB,GAAgB;EACr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;QAAEmB,cAAc,EAAdA,cAAc;QAAE9D,UAAU,EAAVA,UAAU;QAAEiB,IAAI,EAAJA;OAAM,CAAC;;GAE5E,EAAE,CAAC6D,UAAU,CAACrG,eAAe,EAAEuB,UAAU,EAAEiB,IAAI,CAAC,CAAC;EAElD,IAAMvC,iBAAiB,GAAG4G,iBAAW,CAAC;IACpC,OAAO9F,MAAM,CAACC,QAAQ,CAAC8F,OAAO,CACzBjF,iBAAiB,CAAC;MAAEN,UAAU,EAAVA;KAAY,CAAC,gBAAWyE,GAAK,CACrD;GACF,EAAE,CAACzE,UAAU,EAAEyE,GAAG,CAAC,CAAC;EAErB,IAAM9F,MAAM,GAAG2G,iBAAW,CAAC;IACzB,OAAOrG,eAAsB,CAAC;MAAE0D,QAAQ,EAARA;KAAU,CAAC;GAC5C,EAAE,EAAE,CAAC;EAEN,IAAM6C,YAAY,GAAGC,aAAO,CAC1B;IAAA,OAAApG,QAAA,KACKyF,UAAU;MACbpG,iBAAiB,EAAjBA,iBAAiB;MACjBC,MAAM,EAANA;;GACA,EACF,CAACmG,UAAU,EAAEpG,iBAAiB,EAAEC,MAAM,CAAC,CACxC;EAED,OACE+G,6BAACC,YAAY,CAACC,QAAQ;IAACC,KAAK,EAAEL;KAC3Bd,QAAQ,CACa;AAE5B,CAAC;AAED,IAAMiB,YAAY,gBAAGG,mBAAa,CAACzH,iBAAiB,CAAC;AAErD,IAAa0H,QAAQ,GAAG,SAAXA,QAAQA;EACnB,IAAMC,OAAO,GAAGC,gBAAU,CAACN,YAAY,CAAC;EACxC,IAAI,CAACK,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CACb,gEAAgE,CACjE;;EAEH,OAAOF,OAAO;AAChB,CAAC;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"dauth-context-react.cjs.production.min.js","sources":["../src/initialDauthState.ts","../src/reducer/dauth.reducer.ts","../src/reducer/dauth.types.ts","../src/api/utils/config.ts","../src/api/dauth.api.ts","../src/constants.ts","../src/reducer/dauth.actions.ts","../src/index.tsx"],"sourcesContent":["export interface IDauthUser {\n\t_id: string\n\tssid: string\n\tname: string\n\tlastname: string\n\tnickname: string\n\temail: string\n\tis_verified: boolean\n\tlanguage: string\n\tavatar: string\n\tcreatedAt: Date\n\tupdatedAt: Date\n\tlast_login: Date\n}\n\nexport interface IDauthDomain {\n\tname: string\n\tloginRedirect: string\n\tallowedOrigins: string[]\n}\n\nexport interface IDauthState {\n\tuser: IDauthUser\n\tdomain: IDauthDomain\n\tisLoading: boolean\n\tisAuthenticated: boolean\n\tloginWithRedirect: () => void\n\tlogout: () => void\n\tgetAccessToken: () => void\n}\n\nconst initialDauthState: IDauthState = {\n\tuser: {} as IDauthUser,\n\tdomain: {} as IDauthDomain,\n\tisLoading: true,\n\tisAuthenticated: false,\n\tloginWithRedirect: () => { },\n\tlogout: () => { },\n\tgetAccessToken: () => { },\n}\n\nexport default initialDauthState","import * as DauthTypes from './dauth.types'\n\nexport default function userReducer(state: any, action: any) {\n\tconst { type, payload } = action;\n\n\tswitch (type) {\n\t\tcase DauthTypes.LOGIN:\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tuser: payload.user,\n\t\t\t\tdomain: payload.domain,\n\t\t\t\tisAuthenticated: payload.isAuthenticated,\n\t\t\t}\n\n\t\tcase DauthTypes.SET_IS_LOADING:\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tisLoading: payload.isLoading,\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn state\n\t}\n}","export const LOGIN = 'LOGIN';\nexport const SET_IS_LOADING = 'SET_IS_LOADING';","const isLocalhost = Boolean(\n window.location.hostname === \"localhost\" ||\n window.location.hostname === \"[::1]\" ||\n window.location.hostname.match(\n /(192)\\.(168)\\.(1)\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm\n ) ||\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\nexport const apiVersion = \"v1\";\nexport const serverDomain = \"dauth.ovh\";\n\nexport function getServerBasePath({ domainName }: { domainName: string }) {\n const serverPort = 4012;\n const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`\n const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`\n const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;\n return serverBasePath;\n}\n\nexport function getClientBasePath({ domainName }: { domainName: string }) {\n const clientPort = 5185;\n const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`\n const clientProdUrl = `https://${domainName}.${serverDomain}`\n const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;\n return clientBasePath;\n}","import { getServerBasePath } from \"./utils/config\";\n\nexport const getTenantUserAPI = async (domainName: string, ssid: string, token: string): Promise<any> => {\n const params = {\n method: \"GET\",\n headers: {\n Authorization: `${token}`,\n \"Content-Type\": \"application/json\",\n }\n }\n const response = await fetch(`${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`, params)\n const data = await response.json()\n return { response, data }\n}","export const DAUTH_STATE = 'dauth_state';","import { getTenantUserAPI } from '../api/dauth.api';\nimport { DAUTH_STATE } from '../constants';\nimport * as DauthTypes from './dauth.types'\n\ntype TSetDauthStateAction = {\n dispatch: any\n dauth_state: string\n domainName: string\n ssid: string\n}\nexport async function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: TSetDauthStateAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n })\n window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);\n return localStorage.setItem(DAUTH_STATE, dauth_state);\n } else {\n return localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n }\n}\n\ntype TSetAutoLoginAction = {\n dispatch: any\n dauth_state_ls: string\n domainName: string\n ssid: string\n}\nexport async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: TSetAutoLoginAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state_ls);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n })\n localStorage.setItem(DAUTH_STATE, dauth_state_ls);\n } else {\n localStorage.removeItem(DAUTH_STATE);\n }\n\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n }\n}\n\nexport async function setLogoutAction({ dispatch }: { dispatch: any }) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: {},\n domain: {},\n isAuthenticated: false,\n },\n })\n localStorage.removeItem(DAUTH_STATE);\n return dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n}","import React, { useReducer, useMemo, useEffect, useCallback, createContext, useContext } from 'react'\nimport initialDauthState, { IDauthState } from './initialDauthState'\nimport userReducer from './reducer/dauth.reducer'\nimport * as action from \"./reducer/dauth.actions\"\nimport { getClientBasePath } from './api/utils/config'\nimport { DAUTH_STATE } from './constants'\n\ninterface DauthProviderProps {\n domainName: string\n sid: string\n ssid: string\n children: React.ReactNode\n}\n\nexport const DauthProvider: React.FC<DauthProviderProps> = (props: DauthProviderProps) => {\n\tconst { domainName, sid, ssid, children } = props\n\tconst [ds, dispatch] = useReducer(userReducer, initialDauthState)\n const dauthState = ds as IDauthState\n\n\t// Catch login redirect\n\tuseEffect(() => {\n\t\tconst queryString = window.location.search;\n\t\tif (!queryString) return\n\t\tconst urlParams = new URLSearchParams(queryString);\n\t\tconst dauth_state = urlParams.get(DAUTH_STATE);\n\t\tif (dauth_state && !dauthState.isAuthenticated) {\n\t\t\taction.setDauthStateAction({ dispatch, dauth_state, domainName, ssid })\n\t\t}\n\t}, [dauthState.isAuthenticated, domainName, ssid])\n\n\t// Auto Login\n\tuseEffect(() => {\n\t\tconst dauth_state_ls = localStorage.getItem(DAUTH_STATE);\n\t\tif (dauth_state_ls && !dauthState.isAuthenticated) {\n\t\t\taction.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid })\n\t\t}\n\t}, [dauthState.isAuthenticated, domainName, ssid])\n\n\tconst loginWithRedirect = useCallback(() => {\n\t\treturn window.location.replace(`${getClientBasePath({ domainName })}/t-sign/${sid}`);\n\t}, [domainName, sid])\n\n\tconst logout = useCallback(() => {\n\t\treturn action.setLogoutAction({ dispatch })\n\t}, [])\n\n\tconst memoProvider = useMemo(\n\t\t() => ({\n\t\t\t...dauthState,\n\t\t\tloginWithRedirect,\n\t\t\tlogout\n\t\t}), [\n\t\tdauthState,\n\t\tloginWithRedirect,\n\t\tlogout\n\t])\n\n\n\treturn (\n\t\t<DauthContext.Provider value={memoProvider}>\n\t\t\t{children}\n\t\t</DauthContext.Provider>\n\t)\n}\n\nconst DauthContext = createContext(initialDauthState);\n\nexport const useDauth = () => {\n const context = useContext(DauthContext);\n if (!context) {\n throw new Error('useMyContext debe ser utilizado dentro de un MyContextProvider');\n }\n return context;\n};"],"names":["initialDauthState","user","domain","isLoading","isAuthenticated","loginWithRedirect","logout","getAccessToken","userReducer","state","action","payload","type","_extends","isLocalhost","Boolean","window","location","hostname","match","getServerBasePath","_ref","serverLocalUrl","protocol","domainName","getTenantUserAPI","_asyncToGenerator","_regeneratorRuntime","mark","_callee","ssid","token","params","response","wrap","_context","prev","next","method","headers","Authorization","Content-Type","fetch","sent","json","abrupt","data","stop","_x","_x2","_x3","apply","arguments","DAUTH_STATE","_setDauthStateAction","dispatch","dauth_state","getUserFetch","status","history","replaceState","document","title","loginRedirect","localStorage","setItem","removeItem","t0","console","log","finish","_setAutoLoginAction","_callee2","_ref2","dauth_state_ls","_context2","_setLogoutAction","_callee3","_ref3","_context3","DauthContext","createContext","props","sid","children","_useReducer","useReducer","dauthState","useEffect","queryString","search","URLSearchParams","get","getItem","useCallback","replace","clientLocalUrl","memoProvider","useMemo","React","Provider","value","context","useContext","Error"],"mappings":"+hOA+BA,IAAMA,EAAiC,CACtCC,KAAM,GACNC,OAAQ,GACRC,WAAW,EACXC,iBAAiB,EACjBC,kBAAmB,aACnBC,OAAQ,aACRC,eAAgB,uBCpCOC,EAAYC,EAAYC,GAC/C,IAAcC,EAAYD,EAAZC,QAEd,OAF0BD,EAAlBE,MAGP,ICNmB,QDOlB,OAAAC,KACIJ,GACHR,KAAMU,EAAQV,KACdC,OAAQS,EAAQT,OAChBE,gBAAiBO,EAAQP,kBAG3B,ICb4B,iBDc3B,OAAAS,KACIJ,GACHN,UAAWQ,EAAQR,YAGrB,QACC,OAAOM,GErBV,IAAMK,EAAcC,QACW,cAA7BC,OAAOC,SAASC,UACa,UAA7BF,OAAOC,SAASC,UAChBF,OAAOC,SAASC,SAASC,MACvB,2EAEFH,OAAOC,SAASC,SAASC,MACvB,oEAMYC,EAAiBC,OAEzBC,EAAoBN,OAAOC,SAASM,cAAaP,OAAOC,SAASC,SAA7CF,eAG1B,OADuBF,EAAcQ,aAJOD,EAAVG,mCCXvBC,aAAgB,IAAAJ,EAAAK,EAAAC,IAAAC,MAAG,SAAAC,EAAOL,EAAoBM,EAAcC,GAAa,IAAAC,EAAAC,EAAA,OAAAN,IAAAO,eAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE,MAAA,OAOnF,OANKL,EAAS,CACbM,OAAQ,MACRC,QAAS,CACPC,iBAAkBT,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CF,SAEHF,EAAckF,aIciBxE,2BAAwB2D,QJhBxEa,IIiBJ,CAACxE,EAAY2D,IAEV7E,EAASwF,eAAY,WAC1B,gBDyBmC5C,GAAA,OAAA0B,EAAAzB,WAAAC,WCzB5B1C,CAAuB,CAAE6C,SAAAA,MAC9B,IAEG0C,EAAeC,WACpB,WAAA,OAAArF,KACI0E,GACHlF,kBAAAA,EACAC,OAAAA,MACG,CACJiF,EACAlF,EACAC,IAID,OACC6F,gBAACnB,EAAaoB,UAASC,MAAOJ,GAC5Bb,qBAOoB,WACtB,IAAMkB,EAAUC,aAAWvB,GAC3B,IAAKsB,EACH,MAAM,IAAIE,MAAM,kEAElB,OAAOF"}
1
+ {"version":3,"file":"dauth-context-react.cjs.production.min.js","sources":["../src/initialDauthState.ts","../src/reducer/dauth.reducer.ts","../src/reducer/dauth.types.ts","../src/api/utils/config.ts","../src/api/dauth.api.ts","../src/constants.ts","../src/reducer/dauth.actions.ts","../src/index.tsx"],"sourcesContent":["export interface IDauthUser {\n _id: string;\n ssid: string;\n name: string;\n lastname: string;\n nickname: string;\n email: string;\n is_verified: boolean;\n language: string;\n avatar: string;\n createdAt: Date;\n updatedAt: Date;\n last_login: Date;\n}\n\nexport interface IDauthDomain {\n name: string;\n loginRedirect: string;\n allowedOrigins: string[];\n}\n\nexport interface IDauthState {\n user: IDauthUser;\n domain: IDauthDomain;\n isLoading: boolean;\n isAuthenticated: boolean;\n loginWithRedirect: () => void;\n logout: () => void;\n getAccessToken: () => void;\n}\n\nconst initialDauthState: IDauthState = {\n user: {} as IDauthUser,\n domain: {} as IDauthDomain,\n isLoading: true,\n isAuthenticated: false,\n loginWithRedirect: () => {},\n logout: () => {},\n getAccessToken: () => {},\n};\n\nexport default initialDauthState;\n","import * as DauthTypes from './dauth.types';\n\nexport default function userReducer(state: any, action: any) {\n const { type, payload } = action;\n\n switch (type) {\n case DauthTypes.LOGIN:\n return {\n ...state,\n user: payload.user,\n domain: payload.domain,\n isAuthenticated: payload.isAuthenticated,\n };\n\n case DauthTypes.SET_IS_LOADING:\n return {\n ...state,\n isLoading: payload.isLoading,\n };\n\n default:\n return state;\n }\n}\n","export const LOGIN = 'LOGIN';\nexport const SET_IS_LOADING = 'SET_IS_LOADING';\n","const isLocalhost = Boolean(\n window.location.hostname === 'localhost' ||\n window.location.hostname === '[::1]' ||\n window.location.hostname.match(\n /(192)\\.(168)\\.(1)\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm\n ) ||\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\nexport const apiVersion = 'v1';\nexport const serverDomain = 'dauth.ovh';\n\nexport function getServerBasePath({ domainName }: { domainName: string }) {\n const serverPort = 4012;\n const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;\n const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`;\n const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;\n return serverBasePath;\n}\n\nexport function getClientBasePath({ domainName }: { domainName: string }) {\n const clientPort = 5185;\n const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;\n const clientProdUrl = `https://${domainName}.${serverDomain}`;\n const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;\n return clientBasePath;\n}\n","import { getServerBasePath } from './utils/config';\n\nexport const getTenantUserAPI = async (\n domainName: string,\n ssid: string,\n token: string\n): Promise<any> => {\n const params = {\n method: 'GET',\n headers: {\n Authorization: `${token}`,\n 'Content-Type': 'application/json',\n },\n };\n const response = await fetch(\n `${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`,\n params\n );\n const data = await response.json();\n return { response, data };\n};\n","export const DAUTH_STATE = 'dauth_state';\n","import { getTenantUserAPI } from '../api/dauth.api';\nimport { DAUTH_STATE } from '../constants';\nimport * as DauthTypes from './dauth.types';\n\ntype TSetDauthStateAction = {\n dispatch: any;\n dauth_state: string;\n domainName: string;\n ssid: string;\n};\nexport async function setDauthStateAction({\n dispatch,\n dauth_state,\n domainName,\n ssid,\n}: TSetDauthStateAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n });\n window.history.replaceState(\n {},\n document.title,\n getUserFetch.data.domain.loginRedirect\n );\n return localStorage.setItem(DAUTH_STATE, dauth_state);\n } else {\n return localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n }\n}\n\ntype TSetAutoLoginAction = {\n dispatch: any;\n dauth_state_ls: string;\n domainName: string;\n ssid: string;\n};\nexport async function setAutoLoginAction({\n dispatch,\n dauth_state_ls,\n domainName,\n ssid,\n}: TSetAutoLoginAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n try {\n const getUserFetch = await getTenantUserAPI(\n domainName,\n ssid,\n dauth_state_ls\n );\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n });\n localStorage.setItem(DAUTH_STATE, dauth_state_ls);\n } else {\n localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n }\n}\n\nexport async function setLogoutAction({ dispatch }: { dispatch: any }) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: {},\n domain: {},\n isAuthenticated: false,\n },\n });\n localStorage.removeItem(DAUTH_STATE);\n return dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n}\n","import React, {\n useReducer,\n useMemo,\n useEffect,\n useCallback,\n createContext,\n useContext,\n} from 'react';\nimport initialDauthState, { IDauthState } from './initialDauthState';\nimport userReducer from './reducer/dauth.reducer';\nimport * as action from './reducer/dauth.actions';\nimport { getClientBasePath } from './api/utils/config';\nimport { DAUTH_STATE } from './constants';\n\ninterface DauthProviderProps {\n domainName: string;\n sid: string;\n ssid: string;\n children: React.ReactNode;\n}\n\nexport const DauthProvider: React.FC<DauthProviderProps> = (\n props: DauthProviderProps\n) => {\n const { domainName, sid, ssid, children } = props;\n const [ds, dispatch] = useReducer(userReducer, initialDauthState);\n const dauthState = ds as IDauthState;\n\n // Catch login redirect\n useEffect(() => {\n const queryString = window.location.search;\n if (!queryString) return;\n const urlParams = new URLSearchParams(queryString);\n const dauth_state = urlParams.get(DAUTH_STATE);\n if (dauth_state && !dauthState.isAuthenticated) {\n action.setDauthStateAction({ dispatch, dauth_state, domainName, ssid });\n }\n }, [dauthState.isAuthenticated, domainName, ssid]);\n\n // Auto Login\n useEffect(() => {\n const dauth_state_ls = localStorage.getItem(DAUTH_STATE);\n if (dauth_state_ls && !dauthState.isAuthenticated) {\n action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid });\n }\n }, [dauthState.isAuthenticated, domainName, ssid]);\n\n const loginWithRedirect = useCallback(() => {\n return window.location.replace(\n `${getClientBasePath({ domainName })}/t-sign/${sid}`\n );\n }, [domainName, sid]);\n\n const logout = useCallback(() => {\n return action.setLogoutAction({ dispatch });\n }, []);\n\n const memoProvider = useMemo(\n () => ({\n ...dauthState,\n loginWithRedirect,\n logout,\n }),\n [dauthState, loginWithRedirect, logout]\n );\n\n return (\n <DauthContext.Provider value={memoProvider}>\n {children}\n </DauthContext.Provider>\n );\n};\n\nconst DauthContext = createContext(initialDauthState);\n\nexport const useDauth = () => {\n const context = useContext(DauthContext);\n if (!context) {\n throw new Error(\n 'useMyContext debe ser utilizado dentro de un MyContextProvider'\n );\n }\n return context;\n};\n"],"names":["initialDauthState","user","domain","isLoading","isAuthenticated","loginWithRedirect","logout","getAccessToken","userReducer","state","action","payload","type","_extends","isLocalhost","Boolean","window","location","hostname","match","getServerBasePath","_ref","serverLocalUrl","protocol","domainName","getTenantUserAPI","_asyncToGenerator","_regeneratorRuntime","mark","_callee","ssid","token","params","response","wrap","_context","prev","next","method","headers","Authorization","Content-Type","fetch","sent","json","abrupt","data","stop","_x","_x2","_x3","apply","arguments","DAUTH_STATE","_setDauthStateAction","dispatch","dauth_state","getUserFetch","status","history","replaceState","document","title","loginRedirect","localStorage","setItem","removeItem","t0","console","log","finish","_setAutoLoginAction","_callee2","_ref2","dauth_state_ls","_context2","_setLogoutAction","_callee3","_ref3","_context3","DauthContext","createContext","props","sid","children","_useReducer","useReducer","dauthState","useEffect","queryString","search","URLSearchParams","get","getItem","useCallback","replace","clientLocalUrl","memoProvider","useMemo","React","Provider","value","context","useContext","Error"],"mappings":"+hOA+BA,IAAMA,EAAiC,CACrCC,KAAM,GACNC,OAAQ,GACRC,WAAW,EACXC,iBAAiB,EACjBC,kBAAmB,aACnBC,OAAQ,aACRC,eAAgB,uBCpCMC,EAAYC,EAAYC,GAC9C,IAAcC,EAAYD,EAAZC,QAEd,OAF0BD,EAAlBE,MAGN,ICNiB,QDOf,OAAAC,KACKJ,GACHR,KAAMU,EAAQV,KACdC,OAAQS,EAAQT,OAChBE,gBAAiBO,EAAQP,kBAG7B,ICb0B,iBDcxB,OAAAS,KACKJ,GACHN,UAAWQ,EAAQR,YAGvB,QACE,OAAOM,GErBb,IAAMK,EAAcC,QACW,cAA7BC,OAAOC,SAASC,UACe,UAA7BF,OAAOC,SAASC,UAChBF,OAAOC,SAASC,SAASC,MACvB,2EAEFH,OAAOC,SAASC,SAASC,MACvB,oEAMUC,E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AAiBV,aAAa6B,QAAQxC,GACxCqB,IAAmBa,EAAWnF,0BDYE6C,GAAAsB,EAAApB,WAAAC,WCXlC1C,CAA0B,CAAE6C,SAAAA,EAAUmB,eAAAA,EAAgBlD,WAAAA,EAAYM,KAAAA,MAEnE,CAACyD,EAAWnF,gBAAiBoB,EAAYM,IAE5C,IAAMzB,EAAoByF,eAAY,WACpC,OAAO9E,OAAOC,SAAS8E,SJzBnBC,EAAoBhF,OAAOC,SAASM,cAAaP,OAAOC,SAASC,SAA7CF,SAEHF,EAAckF,aIwBVxE,2BAAwB2D,QJ1B7Ca,II4BH,CAACxE,EAAY2D,IAEV7E,EAASwF,eAAY,WACzB,gBDqCiC5C,GAAA,OAAA0B,EAAAzB,WAAAC,WCrC1B1C,CAAuB,CAAE6C,SAAAA,MAC/B,IAEG0C,EAAeC,WACnB,WAAA,OAAArF,KACK0E,GACHlF,kBAAAA,EACAC,OAAAA,MAEF,CAACiF,EAAYlF,EAAmBC,IAGlC,OACE6F,gBAACnB,EAAaoB,UAASC,MAAOJ,GAC3Bb,qBAOiB,WACtB,IAAMkB,EAAUC,aAAWvB,GAC3B,IAAKsB,EACH,MAAM,IAAIE,MACR,kEAGJ,OAAOF"}
@@ -378,9 +378,9 @@ function userReducer(state, action) {
378
378
  }
379
379
  }
380
380
 
381
- var isLocalhost = /*#__PURE__*/Boolean(window.location.hostname === "localhost" || window.location.hostname === "[::1]" || /*#__PURE__*/window.location.hostname.match(/(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm) || /*#__PURE__*/window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
382
- var apiVersion = "v1";
383
- var serverDomain = "dauth.ovh";
381
+ var isLocalhost = /*#__PURE__*/Boolean(window.location.hostname === 'localhost' || window.location.hostname === '[::1]' || /*#__PURE__*/window.location.hostname.match(/(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm) || /*#__PURE__*/window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
382
+ var apiVersion = 'v1';
383
+ var serverDomain = 'dauth.ovh';
384
384
  function getServerBasePath(_ref) {
385
385
  var domainName = _ref.domainName;
386
386
  var serverPort = 4012;
@@ -405,10 +405,10 @@ var getTenantUserAPI = /*#__PURE__*/function () {
405
405
  while (1) switch (_context.prev = _context.next) {
406
406
  case 0:
407
407
  params = {
408
- method: "GET",
408
+ method: 'GET',
409
409
  headers: {
410
410
  Authorization: "" + token,
411
- "Content-Type": "application/json"
411
+ 'Content-Type': 'application/json'
412
412
  }
413
413
  };
414
414
  _context.next = 3;
@@ -1 +1 @@
1
- {"version":3,"file":"dauth-context-react.esm.js","sources":["../src/initialDauthState.ts","../src/reducer/dauth.types.ts","../src/reducer/dauth.reducer.ts","../src/api/utils/config.ts","../src/api/dauth.api.ts","../src/constants.ts","../src/reducer/dauth.actions.ts","../src/index.tsx"],"sourcesContent":["export interface IDauthUser {\n\t_id: string\n\tssid: string\n\tname: string\n\tlastname: string\n\tnickname: string\n\temail: string\n\tis_verified: boolean\n\tlanguage: string\n\tavatar: string\n\tcreatedAt: Date\n\tupdatedAt: Date\n\tlast_login: Date\n}\n\nexport interface IDauthDomain {\n\tname: string\n\tloginRedirect: string\n\tallowedOrigins: string[]\n}\n\nexport interface IDauthState {\n\tuser: IDauthUser\n\tdomain: IDauthDomain\n\tisLoading: boolean\n\tisAuthenticated: boolean\n\tloginWithRedirect: () => void\n\tlogout: () => void\n\tgetAccessToken: () => void\n}\n\nconst initialDauthState: IDauthState = {\n\tuser: {} as IDauthUser,\n\tdomain: {} as IDauthDomain,\n\tisLoading: true,\n\tisAuthenticated: false,\n\tloginWithRedirect: () => { },\n\tlogout: () => { },\n\tgetAccessToken: () => { },\n}\n\nexport default initialDauthState","export const LOGIN = 'LOGIN';\nexport const SET_IS_LOADING = 'SET_IS_LOADING';","import * as DauthTypes from './dauth.types'\n\nexport default function userReducer(state: any, action: any) {\n\tconst { type, payload } = action;\n\n\tswitch (type) {\n\t\tcase DauthTypes.LOGIN:\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tuser: payload.user,\n\t\t\t\tdomain: payload.domain,\n\t\t\t\tisAuthenticated: payload.isAuthenticated,\n\t\t\t}\n\n\t\tcase DauthTypes.SET_IS_LOADING:\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tisLoading: payload.isLoading,\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn state\n\t}\n}","const isLocalhost = Boolean(\n window.location.hostname === \"localhost\" ||\n window.location.hostname === \"[::1]\" ||\n window.location.hostname.match(\n /(192)\\.(168)\\.(1)\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm\n ) ||\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\nexport const apiVersion = \"v1\";\nexport const serverDomain = \"dauth.ovh\";\n\nexport function getServerBasePath({ domainName }: { domainName: string }) {\n const serverPort = 4012;\n const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`\n const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`\n const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;\n return serverBasePath;\n}\n\nexport function getClientBasePath({ domainName }: { domainName: string }) {\n const clientPort = 5185;\n const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`\n const clientProdUrl = `https://${domainName}.${serverDomain}`\n const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;\n return clientBasePath;\n}","import { getServerBasePath } from \"./utils/config\";\n\nexport const getTenantUserAPI = async (domainName: string, ssid: string, token: string): Promise<any> => {\n const params = {\n method: \"GET\",\n headers: {\n Authorization: `${token}`,\n \"Content-Type\": \"application/json\",\n }\n }\n const response = await fetch(`${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`, params)\n const data = await response.json()\n return { response, data }\n}","export const DAUTH_STATE = 'dauth_state';","import { getTenantUserAPI } from '../api/dauth.api';\nimport { DAUTH_STATE } from '../constants';\nimport * as DauthTypes from './dauth.types'\n\ntype TSetDauthStateAction = {\n dispatch: any\n dauth_state: string\n domainName: string\n ssid: string\n}\nexport async function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: TSetDauthStateAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n })\n window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);\n return localStorage.setItem(DAUTH_STATE, dauth_state);\n } else {\n return localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n }\n}\n\ntype TSetAutoLoginAction = {\n dispatch: any\n dauth_state_ls: string\n domainName: string\n ssid: string\n}\nexport async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: TSetAutoLoginAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state_ls);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n })\n localStorage.setItem(DAUTH_STATE, dauth_state_ls);\n } else {\n localStorage.removeItem(DAUTH_STATE);\n }\n\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n }\n}\n\nexport async function setLogoutAction({ dispatch }: { dispatch: any }) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: {},\n domain: {},\n isAuthenticated: false,\n },\n })\n localStorage.removeItem(DAUTH_STATE);\n return dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })\n}","import React, { useReducer, useMemo, useEffect, useCallback, createContext, useContext } from 'react'\nimport initialDauthState, { IDauthState } from './initialDauthState'\nimport userReducer from './reducer/dauth.reducer'\nimport * as action from \"./reducer/dauth.actions\"\nimport { getClientBasePath } from './api/utils/config'\nimport { DAUTH_STATE } from './constants'\n\ninterface DauthProviderProps {\n domainName: string\n sid: string\n ssid: string\n children: React.ReactNode\n}\n\nexport const DauthProvider: React.FC<DauthProviderProps> = (props: DauthProviderProps) => {\n\tconst { domainName, sid, ssid, children } = props\n\tconst [ds, dispatch] = useReducer(userReducer, initialDauthState)\n const dauthState = ds as IDauthState\n\n\t// Catch login redirect\n\tuseEffect(() => {\n\t\tconst queryString = window.location.search;\n\t\tif (!queryString) return\n\t\tconst urlParams = new URLSearchParams(queryString);\n\t\tconst dauth_state = urlParams.get(DAUTH_STATE);\n\t\tif (dauth_state && !dauthState.isAuthenticated) {\n\t\t\taction.setDauthStateAction({ dispatch, dauth_state, domainName, ssid })\n\t\t}\n\t}, [dauthState.isAuthenticated, domainName, ssid])\n\n\t// Auto Login\n\tuseEffect(() => {\n\t\tconst dauth_state_ls = localStorage.getItem(DAUTH_STATE);\n\t\tif (dauth_state_ls && !dauthState.isAuthenticated) {\n\t\t\taction.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid })\n\t\t}\n\t}, [dauthState.isAuthenticated, domainName, ssid])\n\n\tconst loginWithRedirect = useCallback(() => {\n\t\treturn window.location.replace(`${getClientBasePath({ domainName })}/t-sign/${sid}`);\n\t}, [domainName, sid])\n\n\tconst logout = useCallback(() => {\n\t\treturn action.setLogoutAction({ dispatch })\n\t}, [])\n\n\tconst memoProvider = useMemo(\n\t\t() => ({\n\t\t\t...dauthState,\n\t\t\tloginWithRedirect,\n\t\t\tlogout\n\t\t}), [\n\t\tdauthState,\n\t\tloginWithRedirect,\n\t\tlogout\n\t])\n\n\n\treturn (\n\t\t<DauthContext.Provider value={memoProvider}>\n\t\t\t{children}\n\t\t</DauthContext.Provider>\n\t)\n}\n\nconst DauthContext = createContext(initialDauthState);\n\nexport const useDauth = () => {\n const context = useContext(DauthContext);\n if (!context) {\n throw new Error('useMyContext debe ser utilizado dentro de un MyContextProvider');\n }\n return context;\n};"],"names":["initialDauthState","user","domain","isLoading","isAuthenticated","loginWithRedirect","logout","getAccessToken","LOGIN","SET_IS_LOADING","userReducer","state","action","type","payload","DauthTypes","_extends","isLocalhost","Boolean","window","location","hostname","match","apiVersion","serverDomain","getServerBasePath","_ref","domainName","serverPort","serverLocalUrl","protocol","serverProdUrl","serverBasePath","getClientBasePath","_ref2","clientPort","clientLocalUrl","clientProdUrl","clientBasePath","getTenantUserAPI","_asyncToGenerator","_regeneratorRuntime","mark","_callee","ssid","token","params","response","data","wrap","_callee$","_context","prev","next","method","headers","Authorization","fetch","sent","json","abrupt","stop","_x","_x2","_x3","apply","arguments","DAUTH_STATE","setDauthStateAction","_setDauthStateAction","dispatch","dauth_state","getUserFetch","status","history","replaceState","document","title","loginRedirect","localStorage","setItem","removeItem","t0","console","log","finish","setAutoLoginAction","_setAutoLoginAction","_callee2","dauth_state_ls","_callee2$","_context2","setLogoutAction","_setLogoutAction","_callee3","_ref3","_callee3$","_context3","DauthProvider","props","sid","children","_useReducer","useReducer","ds","dauthState","useEffect","queryString","search","urlParams","URLSearchParams","get","getItem","useCallback","replace","memoProvider","useMemo","React","DauthContext","Provider","value","createContext","useDauth","context","useContext","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAY,gBAAGG,aAAa,CAACzH,iBAAiB,CAAC;AAErD,IAAa0H,QAAQ,GAAG,SAAXA,QAAQA;EACnB,IAAMC,OAAO,GAAGC,UAAU,CAACN,YAAY,CAAC;EACxC,IAAI,CAACK,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CAAC,gEAAgE,CAAC;;EAEnF,OAAOF,OAAO;AAChB,CAAC;;;;"}
1
+ {"version":3,"file":"dauth-context-react.esm.js","sources":["../src/initialDauthState.ts","../src/reducer/dauth.types.ts","../src/reducer/dauth.reducer.ts","../src/api/utils/config.ts","../src/api/dauth.api.ts","../src/constants.ts","../src/reducer/dauth.actions.ts","../src/index.tsx"],"sourcesContent":["export interface IDauthUser {\n _id: string;\n ssid: string;\n name: string;\n lastname: string;\n nickname: string;\n email: string;\n is_verified: boolean;\n language: string;\n avatar: string;\n createdAt: Date;\n updatedAt: Date;\n last_login: Date;\n}\n\nexport interface IDauthDomain {\n name: string;\n loginRedirect: string;\n allowedOrigins: string[];\n}\n\nexport interface IDauthState {\n user: IDauthUser;\n domain: IDauthDomain;\n isLoading: boolean;\n isAuthenticated: boolean;\n loginWithRedirect: () => void;\n logout: () => void;\n getAccessToken: () => void;\n}\n\nconst initialDauthState: IDauthState = {\n user: {} as IDauthUser,\n domain: {} as IDauthDomain,\n isLoading: true,\n isAuthenticated: false,\n loginWithRedirect: () => {},\n logout: () => {},\n getAccessToken: () => {},\n};\n\nexport default initialDauthState;\n","export const LOGIN = 'LOGIN';\nexport const SET_IS_LOADING = 'SET_IS_LOADING';\n","import * as DauthTypes from './dauth.types';\n\nexport default function userReducer(state: any, action: any) {\n const { type, payload } = action;\n\n switch (type) {\n case DauthTypes.LOGIN:\n return {\n ...state,\n user: payload.user,\n domain: payload.domain,\n isAuthenticated: payload.isAuthenticated,\n };\n\n case DauthTypes.SET_IS_LOADING:\n return {\n ...state,\n isLoading: payload.isLoading,\n };\n\n default:\n return state;\n }\n}\n","const isLocalhost = Boolean(\n window.location.hostname === 'localhost' ||\n window.location.hostname === '[::1]' ||\n window.location.hostname.match(\n /(192)\\.(168)\\.(1)\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm\n ) ||\n window.location.hostname.match(\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n )\n);\nexport const apiVersion = 'v1';\nexport const serverDomain = 'dauth.ovh';\n\nexport function getServerBasePath({ domainName }: { domainName: string }) {\n const serverPort = 4012;\n const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;\n const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`;\n const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;\n return serverBasePath;\n}\n\nexport function getClientBasePath({ domainName }: { domainName: string }) {\n const clientPort = 5185;\n const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;\n const clientProdUrl = `https://${domainName}.${serverDomain}`;\n const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;\n return clientBasePath;\n}\n","import { getServerBasePath } from './utils/config';\n\nexport const getTenantUserAPI = async (\n domainName: string,\n ssid: string,\n token: string\n): Promise<any> => {\n const params = {\n method: 'GET',\n headers: {\n Authorization: `${token}`,\n 'Content-Type': 'application/json',\n },\n };\n const response = await fetch(\n `${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`,\n params\n );\n const data = await response.json();\n return { response, data };\n};\n","export const DAUTH_STATE = 'dauth_state';\n","import { getTenantUserAPI } from '../api/dauth.api';\nimport { DAUTH_STATE } from '../constants';\nimport * as DauthTypes from './dauth.types';\n\ntype TSetDauthStateAction = {\n dispatch: any;\n dauth_state: string;\n domainName: string;\n ssid: string;\n};\nexport async function setDauthStateAction({\n dispatch,\n dauth_state,\n domainName,\n ssid,\n}: TSetDauthStateAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n try {\n const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n });\n window.history.replaceState(\n {},\n document.title,\n getUserFetch.data.domain.loginRedirect\n );\n return localStorage.setItem(DAUTH_STATE, dauth_state);\n } else {\n return localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n }\n}\n\ntype TSetAutoLoginAction = {\n dispatch: any;\n dauth_state_ls: string;\n domainName: string;\n ssid: string;\n};\nexport async function setAutoLoginAction({\n dispatch,\n dauth_state_ls,\n domainName,\n ssid,\n}: TSetAutoLoginAction) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n try {\n const getUserFetch = await getTenantUserAPI(\n domainName,\n ssid,\n dauth_state_ls\n );\n if (getUserFetch.response.status === 200) {\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: getUserFetch.data.user,\n domain: getUserFetch.data.domain,\n isAuthenticated: true,\n },\n });\n localStorage.setItem(DAUTH_STATE, dauth_state_ls);\n } else {\n localStorage.removeItem(DAUTH_STATE);\n }\n } catch (error) {\n localStorage.removeItem(DAUTH_STATE);\n console.log(error);\n } finally {\n dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n }\n}\n\nexport async function setLogoutAction({ dispatch }: { dispatch: any }) {\n dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });\n dispatch({\n type: DauthTypes.LOGIN,\n payload: {\n user: {},\n domain: {},\n isAuthenticated: false,\n },\n });\n localStorage.removeItem(DAUTH_STATE);\n return dispatch({\n type: DauthTypes.SET_IS_LOADING,\n payload: { isLoading: false },\n });\n}\n","import React, {\n useReducer,\n useMemo,\n useEffect,\n useCallback,\n createContext,\n useContext,\n} from 'react';\nimport initialDauthState, { IDauthState } from './initialDauthState';\nimport userReducer from './reducer/dauth.reducer';\nimport * as action from './reducer/dauth.actions';\nimport { getClientBasePath } from './api/utils/config';\nimport { DAUTH_STATE } from './constants';\n\ninterface DauthProviderProps {\n domainName: string;\n sid: string;\n ssid: string;\n children: React.ReactNode;\n}\n\nexport const DauthProvider: React.FC<DauthProviderProps> = (\n props: DauthProviderProps\n) => {\n const { domainName, sid, ssid, children } = props;\n const [ds, dispatch] = useReducer(userReducer, initialDauthState);\n const dauthState = ds as IDauthState;\n\n // Catch login redirect\n useEffect(() => {\n const queryString = window.location.search;\n if (!queryString) return;\n const urlParams = new URLSearchParams(queryString);\n const dauth_state = urlParams.get(DAUTH_STATE);\n if (dauth_state && !dauthState.isAuthenticated) {\n action.setDauthStateAction({ dispatch, dauth_state, domainName, ssid });\n }\n }, [dauthState.isAuthenticated, domainName, ssid]);\n\n // Auto Login\n useEffect(() => {\n const dauth_state_ls = localStorage.getItem(DAUTH_STATE);\n if (dauth_state_ls && !dauthState.isAuthenticated) {\n action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid });\n }\n }, [dauthState.isAuthenticated, domainName, ssid]);\n\n const loginWithRedirect = useCallback(() => {\n return window.location.replace(\n `${getClientBasePath({ domainName })}/t-sign/${sid}`\n );\n }, [domainName, sid]);\n\n const logout = useCallback(() => {\n return action.setLogoutAction({ dispatch });\n }, []);\n\n const memoProvider = useMemo(\n () => ({\n ...dauthState,\n loginWithRedirect,\n logout,\n }),\n [dauthState, loginWithRedirect, logout]\n );\n\n return (\n <DauthContext.Provider value={memoProvider}>\n {children}\n </DauthContext.Provider>\n );\n};\n\nconst DauthContext = createContext(initialDauthState);\n\nexport const useDauth = () => {\n const context = useContext(DauthContext);\n if (!context) {\n throw new Error(\n 'useMyContext debe ser utilizado dentro de un MyContextProvider'\n );\n }\n return context;\n};\n"],"names":["initialDauthState","user","domain","isLoading","isAuthenticated","loginWithRedirect","logout","getAccessToken","LOGIN","SET_IS_LOADING","userReducer","state","action","type","payload","DauthTypes","_extends","isLocalhost","Boolean","window","location","hostname","match","apiVersion","serverDomain","getServerBasePath","_ref","domainName","serverPort","serverLocalUrl","protocol","serverProdUrl","serverBasePath","getClientBasePath","_ref2","clientPort","clientLocalUrl","clientProdUrl","clientBasePath","getTenantUserAPI","_asyncToGenerator","_regeneratorRuntime","mark","_callee","ssid","token","params","response","data","wrap","_callee$","_context","prev","next","method","headers","Authorization","fetch","sent","json","abrupt","stop","_x","_x2","_x3","apply","arguments","DAUTH_STATE","setDauthStateAction","_setDauthStateAction","dispatch","dauth_state","getUserFetch","status","history","replaceState","document","title","loginRedirect","localStorage","setItem","removeItem","t0","console","log","finish","setAutoLoginAction","_setAutoLoginAction","_callee2","dauth_state_ls","_callee2$","_context2","setLogoutAction","_setLogoutAction","_callee3","_ref3","_callee3$","_context3","DauthProvider","props","sid","children","_useReducer","useReducer","ds","dauthState","useEffect","queryString","search","urlParams","URLSearchParams","get","getItem","useCallback","replace","memoProvider","useMemo","React","DauthContext","Provider","value","createContext","useDauth","context","useContext","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAMA,iBAAiB,GAAgB;EACrCC,IAAI,EAAE,EAAgB;EACtBC,MAAM,EAAE,EAAkB;EAC1BC,SAAS,EAAE,IAAI;EACfC,eA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CAAC;;GAE5E,EAAE,CAAC6D,UAAU,CAACrG,eAAe,EAAEuB,UAAU,EAAEiB,IAAI,CAAC,CAAC;EAElD,IAAMvC,iBAAiB,GAAG4G,WAAW,CAAC;IACpC,OAAO9F,MAAM,CAACC,QAAQ,CAAC8F,OAAO,CACzBjF,iBAAiB,CAAC;MAAEN,UAAU,EAAVA;KAAY,CAAC,gBAAWyE,GAAK,CACrD;GACF,EAAE,CAACzE,UAAU,EAAEyE,GAAG,CAAC,CAAC;EAErB,IAAM9F,MAAM,GAAG2G,WAAW,CAAC;IACzB,OAAOrG,eAAsB,CAAC;MAAE0D,QAAQ,EAARA;KAAU,CAAC;GAC5C,EAAE,EAAE,CAAC;EAEN,IAAM6C,YAAY,GAAGC,OAAO,CAC1B;IAAA,OAAApG,QAAA,KACKyF,UAAU;MACbpG,iBAAiB,EAAjBA,iBAAiB;MACjBC,MAAM,EAANA;;GACA,EACF,CAACmG,UAAU,EAAEpG,iBAAiB,EAAEC,MAAM,CAAC,CACxC;EAED,OACE+G,oBAACC,YAAY,CAACC,QAAQ;IAACC,KAAK,EAAEL;KAC3Bd,QAAQ,CACa;AAE5B,CAAC;AAED,IAAMiB,YAAY,gBAAGG,aAAa,CAACzH,iBAAiB,CAAC;AAErD,IAAa0H,QAAQ,GAAG,SAAXA,QAAQA;EACnB,IAAMC,OAAO,GAAGC,UAAU,CAACN,YAAY,CAAC;EACxC,IAAI,CAACK,OAAO,EAAE;IACZ,MAAM,IAAIE,KAAK,CACb,gEAAgE,CACjE;;EAEH,OAAOF,OAAO;AAChB,CAAC;;;;"}
@@ -4,14 +4,14 @@ declare type TSetDauthStateAction = {
4
4
  domainName: string;
5
5
  ssid: string;
6
6
  };
7
- export declare function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: TSetDauthStateAction): Promise<void>;
7
+ export declare function setDauthStateAction({ dispatch, dauth_state, domainName, ssid, }: TSetDauthStateAction): Promise<void>;
8
8
  declare type TSetAutoLoginAction = {
9
9
  dispatch: any;
10
10
  dauth_state_ls: string;
11
11
  domainName: string;
12
12
  ssid: string;
13
13
  };
14
- export declare function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: TSetAutoLoginAction): Promise<void>;
14
+ export declare function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid, }: TSetAutoLoginAction): Promise<void>;
15
15
  export declare function setLogoutAction({ dispatch }: {
16
16
  dispatch: any;
17
17
  }): Promise<any>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.3",
2
+ "version": "0.1.4",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -1,14 +1,21 @@
1
- import { getServerBasePath } from "./utils/config";
1
+ import { getServerBasePath } from './utils/config';
2
2
 
3
- export const getTenantUserAPI = async (domainName: string, ssid: string, token: string): Promise<any> => {
3
+ export const getTenantUserAPI = async (
4
+ domainName: string,
5
+ ssid: string,
6
+ token: string
7
+ ): Promise<any> => {
4
8
  const params = {
5
- method: "GET",
9
+ method: 'GET',
6
10
  headers: {
7
11
  Authorization: `${token}`,
8
- "Content-Type": "application/json",
9
- }
10
- }
11
- const response = await fetch(`${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`, params)
12
- const data = await response.json()
13
- return { response, data }
14
- }
12
+ 'Content-Type': 'application/json',
13
+ },
14
+ };
15
+ const response = await fetch(
16
+ `${getServerBasePath({ domainName })}/get-tenant-user/${ssid}`,
17
+ params
18
+ );
19
+ const data = await response.json();
20
+ return { response, data };
21
+ };
@@ -1,28 +1,28 @@
1
1
  const isLocalhost = Boolean(
2
- window.location.hostname === "localhost" ||
3
- window.location.hostname === "[::1]" ||
4
- window.location.hostname.match(
5
- /(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
6
- ) ||
7
- window.location.hostname.match(
8
- /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
9
- )
2
+ window.location.hostname === 'localhost' ||
3
+ window.location.hostname === '[::1]' ||
4
+ window.location.hostname.match(
5
+ /(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
6
+ ) ||
7
+ window.location.hostname.match(
8
+ /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
9
+ )
10
10
  );
11
- export const apiVersion = "v1";
12
- export const serverDomain = "dauth.ovh";
11
+ export const apiVersion = 'v1';
12
+ export const serverDomain = 'dauth.ovh';
13
13
 
14
14
  export function getServerBasePath({ domainName }: { domainName: string }) {
15
15
  const serverPort = 4012;
16
- const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`
17
- const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`
16
+ const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;
17
+ const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`;
18
18
  const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;
19
19
  return serverBasePath;
20
20
  }
21
21
 
22
22
  export function getClientBasePath({ domainName }: { domainName: string }) {
23
23
  const clientPort = 5185;
24
- const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`
25
- const clientProdUrl = `https://${domainName}.${serverDomain}`
24
+ const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;
25
+ const clientProdUrl = `https://${domainName}.${serverDomain}`;
26
26
  const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;
27
27
  return clientBasePath;
28
- }
28
+ }
package/src/constants.ts CHANGED
@@ -1 +1 @@
1
- export const DAUTH_STATE = 'dauth_state';
1
+ export const DAUTH_STATE = 'dauth_state';
package/src/index.tsx CHANGED
@@ -1,74 +1,84 @@
1
- import React, { useReducer, useMemo, useEffect, useCallback, createContext, useContext } from 'react'
2
- import initialDauthState, { IDauthState } from './initialDauthState'
3
- import userReducer from './reducer/dauth.reducer'
4
- import * as action from "./reducer/dauth.actions"
5
- import { getClientBasePath } from './api/utils/config'
6
- import { DAUTH_STATE } from './constants'
1
+ import React, {
2
+ useReducer,
3
+ useMemo,
4
+ useEffect,
5
+ useCallback,
6
+ createContext,
7
+ useContext,
8
+ } from 'react';
9
+ import initialDauthState, { IDauthState } from './initialDauthState';
10
+ import userReducer from './reducer/dauth.reducer';
11
+ import * as action from './reducer/dauth.actions';
12
+ import { getClientBasePath } from './api/utils/config';
13
+ import { DAUTH_STATE } from './constants';
7
14
 
8
15
  interface DauthProviderProps {
9
- domainName: string
10
- sid: string
11
- ssid: string
12
- children: React.ReactNode
16
+ domainName: string;
17
+ sid: string;
18
+ ssid: string;
19
+ children: React.ReactNode;
13
20
  }
14
21
 
15
- export const DauthProvider: React.FC<DauthProviderProps> = (props: DauthProviderProps) => {
16
- const { domainName, sid, ssid, children } = props
17
- const [ds, dispatch] = useReducer(userReducer, initialDauthState)
18
- const dauthState = ds as IDauthState
22
+ export const DauthProvider: React.FC<DauthProviderProps> = (
23
+ props: DauthProviderProps
24
+ ) => {
25
+ const { domainName, sid, ssid, children } = props;
26
+ const [ds, dispatch] = useReducer(userReducer, initialDauthState);
27
+ const dauthState = ds as IDauthState;
19
28
 
20
- // Catch login redirect
21
- useEffect(() => {
22
- const queryString = window.location.search;
23
- if (!queryString) return
24
- const urlParams = new URLSearchParams(queryString);
25
- const dauth_state = urlParams.get(DAUTH_STATE);
26
- if (dauth_state && !dauthState.isAuthenticated) {
27
- action.setDauthStateAction({ dispatch, dauth_state, domainName, ssid })
28
- }
29
- }, [dauthState.isAuthenticated, domainName, ssid])
29
+ // Catch login redirect
30
+ useEffect(() => {
31
+ const queryString = window.location.search;
32
+ if (!queryString) return;
33
+ const urlParams = new URLSearchParams(queryString);
34
+ const dauth_state = urlParams.get(DAUTH_STATE);
35
+ if (dauth_state && !dauthState.isAuthenticated) {
36
+ action.setDauthStateAction({ dispatch, dauth_state, domainName, ssid });
37
+ }
38
+ }, [dauthState.isAuthenticated, domainName, ssid]);
30
39
 
31
- // Auto Login
32
- useEffect(() => {
33
- const dauth_state_ls = localStorage.getItem(DAUTH_STATE);
34
- if (dauth_state_ls && !dauthState.isAuthenticated) {
35
- action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid })
36
- }
37
- }, [dauthState.isAuthenticated, domainName, ssid])
40
+ // Auto Login
41
+ useEffect(() => {
42
+ const dauth_state_ls = localStorage.getItem(DAUTH_STATE);
43
+ if (dauth_state_ls && !dauthState.isAuthenticated) {
44
+ action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid });
45
+ }
46
+ }, [dauthState.isAuthenticated, domainName, ssid]);
38
47
 
39
- const loginWithRedirect = useCallback(() => {
40
- return window.location.replace(`${getClientBasePath({ domainName })}/t-sign/${sid}`);
41
- }, [domainName, sid])
48
+ const loginWithRedirect = useCallback(() => {
49
+ return window.location.replace(
50
+ `${getClientBasePath({ domainName })}/t-sign/${sid}`
51
+ );
52
+ }, [domainName, sid]);
42
53
 
43
- const logout = useCallback(() => {
44
- return action.setLogoutAction({ dispatch })
45
- }, [])
54
+ const logout = useCallback(() => {
55
+ return action.setLogoutAction({ dispatch });
56
+ }, []);
46
57
 
47
- const memoProvider = useMemo(
48
- () => ({
49
- ...dauthState,
50
- loginWithRedirect,
51
- logout
52
- }), [
53
- dauthState,
54
- loginWithRedirect,
55
- logout
56
- ])
58
+ const memoProvider = useMemo(
59
+ () => ({
60
+ ...dauthState,
61
+ loginWithRedirect,
62
+ logout,
63
+ }),
64
+ [dauthState, loginWithRedirect, logout]
65
+ );
57
66
 
58
-
59
- return (
60
- <DauthContext.Provider value={memoProvider}>
61
- {children}
62
- </DauthContext.Provider>
63
- )
64
- }
67
+ return (
68
+ <DauthContext.Provider value={memoProvider}>
69
+ {children}
70
+ </DauthContext.Provider>
71
+ );
72
+ };
65
73
 
66
74
  const DauthContext = createContext(initialDauthState);
67
75
 
68
76
  export const useDauth = () => {
69
77
  const context = useContext(DauthContext);
70
78
  if (!context) {
71
- throw new Error('useMyContext debe ser utilizado dentro de un MyContextProvider');
79
+ throw new Error(
80
+ 'useMyContext debe ser utilizado dentro de un MyContextProvider'
81
+ );
72
82
  }
73
83
  return context;
74
- };
84
+ };
@@ -1,42 +1,42 @@
1
1
  export interface IDauthUser {
2
- _id: string
3
- ssid: string
4
- name: string
5
- lastname: string
6
- nickname: string
7
- email: string
8
- is_verified: boolean
9
- language: string
10
- avatar: string
11
- createdAt: Date
12
- updatedAt: Date
13
- last_login: Date
2
+ _id: string;
3
+ ssid: string;
4
+ name: string;
5
+ lastname: string;
6
+ nickname: string;
7
+ email: string;
8
+ is_verified: boolean;
9
+ language: string;
10
+ avatar: string;
11
+ createdAt: Date;
12
+ updatedAt: Date;
13
+ last_login: Date;
14
14
  }
15
15
 
16
16
  export interface IDauthDomain {
17
- name: string
18
- loginRedirect: string
19
- allowedOrigins: string[]
17
+ name: string;
18
+ loginRedirect: string;
19
+ allowedOrigins: string[];
20
20
  }
21
21
 
22
22
  export interface IDauthState {
23
- user: IDauthUser
24
- domain: IDauthDomain
25
- isLoading: boolean
26
- isAuthenticated: boolean
27
- loginWithRedirect: () => void
28
- logout: () => void
29
- getAccessToken: () => void
23
+ user: IDauthUser;
24
+ domain: IDauthDomain;
25
+ isLoading: boolean;
26
+ isAuthenticated: boolean;
27
+ loginWithRedirect: () => void;
28
+ logout: () => void;
29
+ getAccessToken: () => void;
30
30
  }
31
31
 
32
32
  const initialDauthState: IDauthState = {
33
- user: {} as IDauthUser,
34
- domain: {} as IDauthDomain,
35
- isLoading: true,
36
- isAuthenticated: false,
37
- loginWithRedirect: () => { },
38
- logout: () => { },
39
- getAccessToken: () => { },
40
- }
33
+ user: {} as IDauthUser,
34
+ domain: {} as IDauthDomain,
35
+ isLoading: true,
36
+ isAuthenticated: false,
37
+ loginWithRedirect: () => {},
38
+ logout: () => {},
39
+ getAccessToken: () => {},
40
+ };
41
41
 
42
- export default initialDauthState
42
+ export default initialDauthState;
@@ -1,15 +1,20 @@
1
1
  import { getTenantUserAPI } from '../api/dauth.api';
2
2
  import { DAUTH_STATE } from '../constants';
3
- import * as DauthTypes from './dauth.types'
3
+ import * as DauthTypes from './dauth.types';
4
4
 
5
5
  type TSetDauthStateAction = {
6
- dispatch: any
7
- dauth_state: string
8
- domainName: string
9
- ssid: string
10
- }
11
- export async function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: TSetDauthStateAction) {
12
- dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })
6
+ dispatch: any;
7
+ dauth_state: string;
8
+ domainName: string;
9
+ ssid: string;
10
+ };
11
+ export async function setDauthStateAction({
12
+ dispatch,
13
+ dauth_state,
14
+ domainName,
15
+ ssid,
16
+ }: TSetDauthStateAction) {
17
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });
13
18
  try {
14
19
  const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);
15
20
  if (getUserFetch.response.status === 200) {
@@ -20,8 +25,12 @@ export async function setDauthStateAction({ dispatch, dauth_state, domainName, s
20
25
  domain: getUserFetch.data.domain,
21
26
  isAuthenticated: true,
22
27
  },
23
- })
24
- window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);
28
+ });
29
+ window.history.replaceState(
30
+ {},
31
+ document.title,
32
+ getUserFetch.data.domain.loginRedirect
33
+ );
25
34
  return localStorage.setItem(DAUTH_STATE, dauth_state);
26
35
  } else {
27
36
  return localStorage.removeItem(DAUTH_STATE);
@@ -30,20 +39,32 @@ export async function setDauthStateAction({ dispatch, dauth_state, domainName, s
30
39
  localStorage.removeItem(DAUTH_STATE);
31
40
  console.log(error);
32
41
  } finally {
33
- dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })
42
+ dispatch({
43
+ type: DauthTypes.SET_IS_LOADING,
44
+ payload: { isLoading: false },
45
+ });
34
46
  }
35
47
  }
36
48
 
37
49
  type TSetAutoLoginAction = {
38
- dispatch: any
39
- dauth_state_ls: string
40
- domainName: string
41
- ssid: string
42
- }
43
- export async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: TSetAutoLoginAction) {
44
- dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })
50
+ dispatch: any;
51
+ dauth_state_ls: string;
52
+ domainName: string;
53
+ ssid: string;
54
+ };
55
+ export async function setAutoLoginAction({
56
+ dispatch,
57
+ dauth_state_ls,
58
+ domainName,
59
+ ssid,
60
+ }: TSetAutoLoginAction) {
61
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });
45
62
  try {
46
- const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state_ls);
63
+ const getUserFetch = await getTenantUserAPI(
64
+ domainName,
65
+ ssid,
66
+ dauth_state_ls
67
+ );
47
68
  if (getUserFetch.response.status === 200) {
48
69
  dispatch({
49
70
  type: DauthTypes.LOGIN,
@@ -52,22 +73,24 @@ export async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName,
52
73
  domain: getUserFetch.data.domain,
53
74
  isAuthenticated: true,
54
75
  },
55
- })
76
+ });
56
77
  localStorage.setItem(DAUTH_STATE, dauth_state_ls);
57
78
  } else {
58
79
  localStorage.removeItem(DAUTH_STATE);
59
80
  }
60
-
61
81
  } catch (error) {
62
82
  localStorage.removeItem(DAUTH_STATE);
63
83
  console.log(error);
64
84
  } finally {
65
- dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })
85
+ dispatch({
86
+ type: DauthTypes.SET_IS_LOADING,
87
+ payload: { isLoading: false },
88
+ });
66
89
  }
67
90
  }
68
91
 
69
92
  export async function setLogoutAction({ dispatch }: { dispatch: any }) {
70
- dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })
93
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });
71
94
  dispatch({
72
95
  type: DauthTypes.LOGIN,
73
96
  payload: {
@@ -75,7 +98,10 @@ export async function setLogoutAction({ dispatch }: { dispatch: any }) {
75
98
  domain: {},
76
99
  isAuthenticated: false,
77
100
  },
78
- })
101
+ });
79
102
  localStorage.removeItem(DAUTH_STATE);
80
- return dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })
81
- }
103
+ return dispatch({
104
+ type: DauthTypes.SET_IS_LOADING,
105
+ payload: { isLoading: false },
106
+ });
107
+ }
@@ -1,24 +1,24 @@
1
- import * as DauthTypes from './dauth.types'
1
+ import * as DauthTypes from './dauth.types';
2
2
 
3
3
  export default function userReducer(state: any, action: any) {
4
- const { type, payload } = action;
4
+ const { type, payload } = action;
5
5
 
6
- switch (type) {
7
- case DauthTypes.LOGIN:
8
- return {
9
- ...state,
10
- user: payload.user,
11
- domain: payload.domain,
12
- isAuthenticated: payload.isAuthenticated,
13
- }
6
+ switch (type) {
7
+ case DauthTypes.LOGIN:
8
+ return {
9
+ ...state,
10
+ user: payload.user,
11
+ domain: payload.domain,
12
+ isAuthenticated: payload.isAuthenticated,
13
+ };
14
14
 
15
- case DauthTypes.SET_IS_LOADING:
16
- return {
17
- ...state,
18
- isLoading: payload.isLoading,
19
- }
15
+ case DauthTypes.SET_IS_LOADING:
16
+ return {
17
+ ...state,
18
+ isLoading: payload.isLoading,
19
+ };
20
20
 
21
- default:
22
- return state
23
- }
24
- }
21
+ default:
22
+ return state;
23
+ }
24
+ }
@@ -1,2 +1,2 @@
1
1
  export const LOGIN = 'LOGIN';
2
- export const SET_IS_LOADING = 'SET_IS_LOADING';
2
+ export const SET_IS_LOADING = 'SET_IS_LOADING';