@iad-os/react-ghost-auth
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -817,2 +817,13 @@ import { jsx, jsxs } from 'react/jsx-runtime'; | ||
setStatus('LOGGING'); | ||
retriveToken(code, code_verifier); | ||
} | ||
else if (isAuthenticated()) { | ||
setStatus('LOGGED'); | ||
} | ||
else { | ||
setStatus('INIT'); | ||
} | ||
}, []); | ||
const retriveToken = (code, code_verifier) => { | ||
if (provider) { | ||
const { client_id, token_endpoint, client_secret, redirect_uri } = provider; | ||
@@ -850,9 +861,6 @@ const BASIC_TOKEN = `Basic ${window.btoa(`${client_id}:${client_secret}`)}`; | ||
} | ||
else if (isAuthenticated()) { | ||
setStatus('LOGGED'); | ||
} | ||
else { | ||
setStatus('INIT'); | ||
throw Error('OIDC Provider not found'); | ||
} | ||
}, []); | ||
}; | ||
const refreshToken = () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -973,2 +981,3 @@ if (provider) { | ||
const { children } = props; | ||
const [showChildren, setShowChildren] = useState(false); | ||
const { login, isAuthenticated, status, providerInfo: providerInfoFn, } = useAuthentication(); | ||
@@ -979,20 +988,20 @@ const providerInfo = providerInfoFn(); | ||
const providers = providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.list; | ||
if (storedProvider !== null && | ||
status !== 'LOGGED' && | ||
status !== 'LOGGING') { | ||
login(storedProvider); | ||
if (status === 'LOGIN' && !isAuthenticated()) { | ||
if (storedProvider !== null) { | ||
setShowChildren(false); | ||
login(storedProvider); | ||
} | ||
else if (!children && (providers === null || providers === void 0 ? void 0 : providers.length) === 1) { | ||
setShowChildren(false); | ||
login(providers[0]); | ||
} | ||
else { | ||
setShowChildren(true); | ||
} | ||
} | ||
else if (!children && | ||
(providers === null || providers === void 0 ? void 0 : providers.length) === 1 && | ||
status === 'LOGIN' && | ||
!isAuthenticated()) { | ||
login(providers[0]); | ||
else { | ||
setShowChildren(false); | ||
} | ||
}, [status]); | ||
return (jsx("div", { children: storedProvider === null && | ||
providerInfo && | ||
providerInfo.list.length > 1 && | ||
!isAuthenticated() && | ||
status === 'LOGIN' && | ||
children })); | ||
return jsx("div", { children: showChildren && children }); | ||
} | ||
@@ -999,0 +1008,0 @@ |
@@ -825,2 +825,13 @@ 'use strict'; | ||
setStatus('LOGGING'); | ||
retriveToken(code, code_verifier); | ||
} | ||
else if (isAuthenticated()) { | ||
setStatus('LOGGED'); | ||
} | ||
else { | ||
setStatus('INIT'); | ||
} | ||
}, []); | ||
const retriveToken = (code, code_verifier) => { | ||
if (provider) { | ||
const { client_id, token_endpoint, client_secret, redirect_uri } = provider; | ||
@@ -858,9 +869,6 @@ const BASIC_TOKEN = `Basic ${window.btoa(`${client_id}:${client_secret}`)}`; | ||
} | ||
else if (isAuthenticated()) { | ||
setStatus('LOGGED'); | ||
} | ||
else { | ||
setStatus('INIT'); | ||
throw Error('OIDC Provider not found'); | ||
} | ||
}, []); | ||
}; | ||
const refreshToken = () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -981,2 +989,3 @@ if (provider) { | ||
const { children } = props; | ||
const [showChildren, setShowChildren] = React.useState(false); | ||
const { login, isAuthenticated, status, providerInfo: providerInfoFn, } = useAuthentication(); | ||
@@ -987,20 +996,20 @@ const providerInfo = providerInfoFn(); | ||
const providers = providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.list; | ||
if (storedProvider !== null && | ||
status !== 'LOGGED' && | ||
status !== 'LOGGING') { | ||
login(storedProvider); | ||
if (status === 'LOGIN' && !isAuthenticated()) { | ||
if (storedProvider !== null) { | ||
setShowChildren(false); | ||
login(storedProvider); | ||
} | ||
else if (!children && (providers === null || providers === void 0 ? void 0 : providers.length) === 1) { | ||
setShowChildren(false); | ||
login(providers[0]); | ||
} | ||
else { | ||
setShowChildren(true); | ||
} | ||
} | ||
else if (!children && | ||
(providers === null || providers === void 0 ? void 0 : providers.length) === 1 && | ||
status === 'LOGIN' && | ||
!isAuthenticated()) { | ||
login(providers[0]); | ||
else { | ||
setShowChildren(false); | ||
} | ||
}, [status]); | ||
return (jsxRuntime.jsx("div", { children: storedProvider === null && | ||
providerInfo && | ||
providerInfo.list.length > 1 && | ||
!isAuthenticated() && | ||
status === 'LOGIN' && | ||
children })); | ||
return jsxRuntime.jsx("div", { children: showChildren && children }); | ||
} | ||
@@ -1007,0 +1016,0 @@ |
{ | ||
"name": "@iad-os/react-ghost-auth", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"maintainers": [ | ||
@@ -5,0 +5,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
172451
1953