dauth-context-react 0.1.0 → 0.1.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dauth-context-react.esm.js","sources":["../src/index.tsx"],"sourcesContent":["import * as React from 'react';\n\n// Delete me\nexport const Thing = () => {\n return <div>the snozzberries taste like snozzberries</div>;\n};\n"],"names":["Thing","React"],"mappings":";;AAEA;IACaA,KAAK,GAAG,SAARA,KAAKA;EAChB,OAAOC,sEAAmD;AAC5D;;;;"}
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\n// export interface IDauthDomain {\n// \tname: string\n// \tloginRedirect: string\n// \tallowedOrigins: string[]\n// }\n\n// export 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\n// const userState = {\n// \t_id: \"\",\n// \tssid: \"\",\n// \tname: \"\",\n// \tlastname: \"\",\n// \tnickname: \"\",\n// \temail: \"\",\n// \tis_verified: false,\n// \tlanguage: \"\",\n// \tavatar: \"\",\n// \tcreatedAt: new Date(),\n// \tupdatedAt: new Date(),\n// \tlast_login: new Date(),\n// }\n\nconst domainState = {\n\tname: \"\",\n\tloginRedirect: \"\",\n\tallowedOrigins: [\"\"],\n}\n\nconst initialDauthState = {\n\tuser: {} as IDauthUser,\n\tdomain: domainState,\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\nexport async function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: { dispatch: any, dauth_state: string, domainName: string, ssid: string }) {\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\nexport async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: { dispatch: any, dauth_state_ls: string, domainName: string, ssid: string }) {\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 * as React from 'react';\nimport { useReducer, useMemo, useEffect, useCallback } from 'react'\nimport initialDauthState 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\n// Delete me\nexport const Thing = () => {\n return <div>the snozzberries taste like snozzberries</div>;\n};\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 [dauthState, dispatch] = useReducer(userReducer, initialDauthState)\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 = React.createContext(initialDauthState);\n\nexport const useDauthContext = () => {\n const context = React.useContext(DauthContext);\n if (!context) {\n throw new Error('useMyContext debe ser utilizado dentro de un MyContextProvider');\n }\n return context;\n};"],"names":["domainState","name","loginRedirect","allowedOrigins","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","localStorage","setItem","removeItem","t0","console","log","finish","setAutoLoginAction","_setAutoLoginAction","_callee2","dauth_state_ls","_callee2$","_context2","setLogoutAction","_setLogoutAction","_callee3","_ref3","_callee3$","_context3","Thing","React","DauthProvider","props","sid","children","_useReducer","useReducer","dauthState","useEffect","queryString","search","urlParams","URLSearchParams","get","getItem","useCallback","replace","memoProvider","useMemo","DauthContext","Provider","value","useDauthContext","context","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAMA,WAAW,GAAG;EACnBC,IAAI,EAAE,EAAE;EACRC,aAAa,EAAE,EAAE;EACjBC,cAAc,EAAE,CAAC,EAAE;CACnB;AAED,IAAMC,iBAAiB,GAAG;EACzBC,IAAI,EAAE,EAAgB;EACtBC,MAAM,EAAEN,WAAW;EACnBO,SAAS,EAAE,IAAI;EACfC,eAAe,EAAE,KAAK;EACtBC,iBAAiB,EAAE,SAAAA,sBAAS;EAC5BC,MAAM,EAAE,SAAAA,WAAS;EACjBC,cAAc,EAAE,SAAAA;CAChB;;AC5DM,IAAMC,KAAK,GAAG,OAAO;AAC5B,AAAO,IAAMC,cAAc,GAAG,gBAAgB;;SCCtBC,WAAWA,CAACC,KAAU,EAAEC,MAAW;EAC1D,IAAQC,IAAI,GAAcD,MAAM,CAAxBC,IAAI;IAAEC,OAAO,GAAKF,MAAM,CAAlBE,OAAO;EAErB,QAAQD,IAAI;IACX,KAAKE,KAAgB;MACpB,OAAAC,QAAA,KACIL,KAAK;QACRV,I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W,CAAC;IAC1B,OAAOrG,eAAsB,CAAC;MAAE0D,QAAQ,EAARA;KAAU,CAAC;GAC3C,EAAE,EAAE,CAAC;EAEN,IAAM6C,YAAY,GAAGC,OAAO,CAC3B;IAAA,OAAApG,QAAA,KACIyF,UAAU;MACbpG,iBAAiB,EAAjBA,iBAAiB;MACjBC,MAAM,EAANA;;GACC,EAAE,CACJmG,UAAU,EACVpG,iBAAiB,EACjBC,MAAM,CACN,CAAC;EAGF,OACC4F,cAACmB,YAAY,CAACC,QAAQ;IAACC,KAAK,EAAEJ;KAC5Bb,QAAQ,CACc;AAE1B,CAAC;AAED,IAAMe,YAAY,gBAAGnB,aAAmB,CAAClG,iBAAiB,CAAC;AAE3D,IAAawH,eAAe,GAAG,SAAlBA,eAAeA;EAC1B,IAAMC,OAAO,GAAGvB,UAAgB,CAACmB,YAAY,CAAC;EAC9C,IAAI,CAACI,OAAO,EAAE;IACZ,MAAM,IAAIC,KAAK,CAAC,gEAAgE,CAAC;;EAEnF,OAAOD,OAAO;AAChB,CAAC;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,36 @@
1
1
  import * as React from 'react';
2
2
  export declare const Thing: () => React.JSX.Element;
3
+ interface DauthProviderProps {
4
+ domainName: string;
5
+ sid: string;
6
+ ssid: string;
7
+ children: React.ReactNode;
8
+ }
9
+ export declare const DauthProvider: React.FC<DauthProviderProps>;
10
+ export declare const useDauthContext: () => {
11
+ user: {
12
+ _id: string;
13
+ ssid: string;
14
+ name: string;
15
+ lastname: string;
16
+ nickname: string;
17
+ email: string;
18
+ is_verified: boolean;
19
+ language: string;
20
+ avatar: string;
21
+ createdAt: Date;
22
+ updatedAt: Date;
23
+ last_login: Date;
24
+ };
25
+ domain: {
26
+ name: string;
27
+ loginRedirect: string;
28
+ allowedOrigins: string[];
29
+ };
30
+ isLoading: boolean;
31
+ isAuthenticated: boolean;
32
+ loginWithRedirect: () => void;
33
+ logout: () => void;
34
+ getAccessToken: () => void;
35
+ };
36
+ export {};
@@ -0,0 +1,28 @@
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;
14
+ }
15
+ declare const initialDauthState: {
16
+ user: IDauthUser;
17
+ domain: {
18
+ name: string;
19
+ loginRedirect: string;
20
+ allowedOrigins: string[];
21
+ };
22
+ isLoading: boolean;
23
+ isAuthenticated: boolean;
24
+ loginWithRedirect: () => void;
25
+ logout: () => void;
26
+ getAccessToken: () => void;
27
+ };
28
+ export default initialDauthState;
@@ -0,0 +1,15 @@
1
+ export declare function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: {
2
+ dispatch: any;
3
+ dauth_state: string;
4
+ domainName: string;
5
+ ssid: string;
6
+ }): Promise<void>;
7
+ export declare function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: {
8
+ dispatch: any;
9
+ dauth_state_ls: string;
10
+ domainName: string;
11
+ ssid: string;
12
+ }): Promise<void>;
13
+ export declare function setLogoutAction({ dispatch }: {
14
+ dispatch: any;
15
+ }): Promise<any>;
@@ -0,0 +1 @@
1
+ export default function userReducer(state: any, action: any): any;
@@ -0,0 +1,2 @@
1
+ export declare const LOGIN = "LOGIN";
2
+ export declare const SET_IS_LOADING = "SET_IS_LOADING";
package/package.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.1.0","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","files":["dist","src"],"engines":{"node":">=10"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test --passWithNoTests","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"peerDependencies":{"react":">=16"},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"name":"dauth-context-react","author":"David T. Pizarro Frick","module":"dist/dauth-context-react.esm.js","size-limit":[{"path":"dist/dauth-context-react.cjs.production.min.js","limit":"10 KB"},{"path":"dist/dauth-context-react.esm.js","limit":"10 KB"}],"devDependencies":{"@size-limit/preset-small-lib":"^11.0.2","@types/react":"^18.2.55","@types/react-dom":"^18.2.19","husky":"^9.0.10","react":"^18.2.0","react-dom":"^18.2.0","size-limit":"^11.0.2","tsdx":"^0.14.1","tslib":"^2.6.2","typescript":"^3.9.10"}}
1
+ {"version":"0.1.2","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","files":["dist","src"],"engines":{"node":">=10"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test --passWithNoTests","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"peerDependencies":{"react":">=16"},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"name":"dauth-context-react","author":"David T. Pizarro Frick","module":"dist/dauth-context-react.esm.js","size-limit":[{"path":"dist/dauth-context-react.cjs.production.min.js","limit":"10 KB"},{"path":"dist/dauth-context-react.esm.js","limit":"10 KB"}],"devDependencies":{"@size-limit/preset-small-lib":"^11.0.2","@types/react":"^18.2.55","@types/react-dom":"^18.2.19","husky":"^9.0.10","react":"^18.2.0","react-dom":"^18.2.0","size-limit":"^11.0.2","tsdx":"^0.14.1","tslib":"^2.6.2","typescript":"^3.9.10"}}
@@ -0,0 +1,14 @@
1
+ import { getServerBasePath } from "./utils/config";
2
+
3
+ export const getTenantUserAPI = async (domainName: string, ssid: string, token: string): Promise<any> => {
4
+ const params = {
5
+ method: "GET",
6
+ headers: {
7
+ 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
+ }
@@ -0,0 +1,28 @@
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
+ )
10
+ );
11
+ export const apiVersion = "v1";
12
+ export const serverDomain = "dauth.ovh";
13
+
14
+ export function getServerBasePath({ domainName }: { domainName: string }) {
15
+ const serverPort = 4012;
16
+ const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`
17
+ const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`
18
+ const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;
19
+ return serverBasePath;
20
+ }
21
+
22
+ export function getClientBasePath({ domainName }: { domainName: string }) {
23
+ const clientPort = 5185;
24
+ const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`
25
+ const clientProdUrl = `https://${domainName}.${serverDomain}`
26
+ const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;
27
+ return clientBasePath;
28
+ }
@@ -0,0 +1 @@
1
+ export const DAUTH_STATE = 'dauth_state';
package/src/index.tsx CHANGED
@@ -1,6 +1,79 @@
1
1
  import * as React from 'react';
2
+ import { useReducer, useMemo, useEffect, useCallback } from 'react'
3
+ import initialDauthState from './initialDauthState'
4
+ import userReducer from './reducer/dauth.reducer'
5
+ import * as action from "./reducer/dauth.actions"
6
+ import { getClientBasePath } from './api/utils/config'
7
+ import { DAUTH_STATE } from './constants'
2
8
 
3
9
  // Delete me
4
10
  export const Thing = () => {
5
11
  return <div>the snozzberries taste like snozzberries</div>;
6
12
  };
13
+
14
+ interface DauthProviderProps {
15
+ domainName: string
16
+ sid: string
17
+ ssid: string
18
+ children: React.ReactNode
19
+ }
20
+
21
+ export const DauthProvider: React.FC<DauthProviderProps> = (props: DauthProviderProps) => {
22
+ const { domainName, sid, ssid, children } = props
23
+ const [dauthState, dispatch] = useReducer(userReducer, initialDauthState)
24
+
25
+ // Catch login redirect
26
+ useEffect(() => {
27
+ const queryString = window.location.search;
28
+ if (!queryString) return
29
+ const urlParams = new URLSearchParams(queryString);
30
+ const dauth_state = urlParams.get(DAUTH_STATE);
31
+ if (dauth_state && !dauthState.isAuthenticated) {
32
+ action.setDauthStateAction({ dispatch, dauth_state, domainName, ssid })
33
+ }
34
+ }, [dauthState.isAuthenticated, domainName, ssid])
35
+
36
+ // Auto Login
37
+ useEffect(() => {
38
+ const dauth_state_ls = localStorage.getItem(DAUTH_STATE);
39
+ if (dauth_state_ls && !dauthState.isAuthenticated) {
40
+ action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid })
41
+ }
42
+ }, [dauthState.isAuthenticated, domainName, ssid])
43
+
44
+ const loginWithRedirect = useCallback(() => {
45
+ return window.location.replace(`${getClientBasePath({ domainName })}/t-sign/${sid}`);
46
+ }, [domainName, sid])
47
+
48
+ const logout = useCallback(() => {
49
+ return action.setLogoutAction({ dispatch })
50
+ }, [])
51
+
52
+ const memoProvider = useMemo(
53
+ () => ({
54
+ ...dauthState,
55
+ loginWithRedirect,
56
+ logout
57
+ }), [
58
+ dauthState,
59
+ loginWithRedirect,
60
+ logout
61
+ ])
62
+
63
+
64
+ return (
65
+ <DauthContext.Provider value={memoProvider}>
66
+ {children}
67
+ </DauthContext.Provider>
68
+ )
69
+ }
70
+
71
+ const DauthContext = React.createContext(initialDauthState);
72
+
73
+ export const useDauthContext = () => {
74
+ const context = React.useContext(DauthContext);
75
+ if (!context) {
76
+ throw new Error('useMyContext debe ser utilizado dentro de un MyContextProvider');
77
+ }
78
+ return context;
79
+ };
@@ -0,0 +1,63 @@
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
14
+ }
15
+
16
+ // export interface IDauthDomain {
17
+ // name: string
18
+ // loginRedirect: string
19
+ // allowedOrigins: string[]
20
+ // }
21
+
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
30
+ // }
31
+
32
+ // const userState = {
33
+ // _id: "",
34
+ // ssid: "",
35
+ // name: "",
36
+ // lastname: "",
37
+ // nickname: "",
38
+ // email: "",
39
+ // is_verified: false,
40
+ // language: "",
41
+ // avatar: "",
42
+ // createdAt: new Date(),
43
+ // updatedAt: new Date(),
44
+ // last_login: new Date(),
45
+ // }
46
+
47
+ const domainState = {
48
+ name: "",
49
+ loginRedirect: "",
50
+ allowedOrigins: [""],
51
+ }
52
+
53
+ const initialDauthState = {
54
+ user: {} as IDauthUser,
55
+ domain: domainState,
56
+ isLoading: true,
57
+ isAuthenticated: false,
58
+ loginWithRedirect: () => { },
59
+ logout: () => { },
60
+ getAccessToken: () => { },
61
+ }
62
+
63
+ export default initialDauthState
@@ -0,0 +1,69 @@
1
+ import { getTenantUserAPI } from '../api/dauth.api';
2
+ import { DAUTH_STATE } from '../constants';
3
+ import * as DauthTypes from './dauth.types'
4
+
5
+ export async function setDauthStateAction({ dispatch, dauth_state, domainName, ssid }: { dispatch: any, dauth_state: string, domainName: string, ssid: string }) {
6
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })
7
+ try {
8
+ const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state);
9
+ if (getUserFetch.response.status === 200) {
10
+ dispatch({
11
+ type: DauthTypes.LOGIN,
12
+ payload: {
13
+ user: getUserFetch.data.user,
14
+ domain: getUserFetch.data.domain,
15
+ isAuthenticated: true,
16
+ },
17
+ })
18
+ window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);
19
+ return localStorage.setItem(DAUTH_STATE, dauth_state);
20
+ } else {
21
+ return localStorage.removeItem(DAUTH_STATE);
22
+ }
23
+ } catch (error) {
24
+ localStorage.removeItem(DAUTH_STATE);
25
+ console.log(error);
26
+ } finally {
27
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })
28
+ }
29
+ }
30
+
31
+ export async function setAutoLoginAction({ dispatch, dauth_state_ls, domainName, ssid }: { dispatch: any, dauth_state_ls: string, domainName: string, ssid: string }) {
32
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })
33
+ try {
34
+ const getUserFetch = await getTenantUserAPI(domainName, ssid, dauth_state_ls);
35
+ if (getUserFetch.response.status === 200) {
36
+ dispatch({
37
+ type: DauthTypes.LOGIN,
38
+ payload: {
39
+ user: getUserFetch.data.user,
40
+ domain: getUserFetch.data.domain,
41
+ isAuthenticated: true,
42
+ },
43
+ })
44
+ localStorage.setItem(DAUTH_STATE, dauth_state_ls);
45
+ } else {
46
+ localStorage.removeItem(DAUTH_STATE);
47
+ }
48
+
49
+ } catch (error) {
50
+ localStorage.removeItem(DAUTH_STATE);
51
+ console.log(error);
52
+ } finally {
53
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })
54
+ }
55
+ }
56
+
57
+ export async function setLogoutAction({ dispatch }: { dispatch: any }) {
58
+ dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } })
59
+ dispatch({
60
+ type: DauthTypes.LOGIN,
61
+ payload: {
62
+ user: {},
63
+ domain: {},
64
+ isAuthenticated: false,
65
+ },
66
+ })
67
+ localStorage.removeItem(DAUTH_STATE);
68
+ return dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: false } })
69
+ }
@@ -0,0 +1,24 @@
1
+ import * as DauthTypes from './dauth.types'
2
+
3
+ export default function userReducer(state: any, action: any) {
4
+ const { type, payload } = action;
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
+ }
14
+
15
+ case DauthTypes.SET_IS_LOADING:
16
+ return {
17
+ ...state,
18
+ isLoading: payload.isLoading,
19
+ }
20
+
21
+ default:
22
+ return state
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ export const LOGIN = 'LOGIN';
2
+ export const SET_IS_LOADING = 'SET_IS_LOADING';