Skip to content

Commit

Permalink
add debug console.logs
Browse files Browse the repository at this point in the history
  • Loading branch information
richpryce committed Nov 3, 2022
1 parent 4af8e4a commit 1d10a98
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/AppSwitcher/LoginComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const LoginComponent:React.FC<LoginComponentProps> = (props) => {
const [loginExpiryCount, setLoginExpiryCount] = useState<string>("");

const overrideRefreshLoginRef = useRef(props.overrideRefreshLogin);

console.log(overrideRefreshLoginRef)
const classes = useStyles();

const oAuthContext = useContext(OAuthContext);
Expand All @@ -54,7 +54,7 @@ const LoginComponent:React.FC<LoginComponentProps> = (props) => {

useEffect(()=>{
const intervalTimerId = window.setInterval(checkExpiryHandler, props.checkInterval ?? 60000);

console.log("useEffect count")
return (()=>{
window.clearInterval(intervalTimerId);
})
Expand All @@ -78,6 +78,7 @@ const LoginComponent:React.FC<LoginComponentProps> = (props) => {
const nowTime = new Date().getTime() / 1000; //assume time is in seconds
const expiry = userContext.profile.exp;
const timeToGo = expiry - nowTime;
console.log("updateCountdownHandler\n", "nowtime: ", nowTime, "\n", "expiry: ", expiry, "\n", "timeToGo: ", timeToGo)

if (timeToGo > 1) {
setLoginExpiryCount(`expires in ${Math.ceil(timeToGo)}s`);
Expand All @@ -94,11 +95,13 @@ const LoginComponent:React.FC<LoginComponentProps> = (props) => {
* is ignored but it is used in testing to ensure that the component state is only checked after it has been set.
*/
const checkExpiryHandler = () => {
console.log("CHECK-EXPIRY")
if (userContext.profile && oAuthContext) {
const nowTime = new Date().getTime() / 1000; //assume time is in seconds
//we know that it is not null due to above check
const expiry = userContext.profile.exp;
const timeToGo = expiry - nowTime;
console.log("checkExpiryHandler\n", "nowtime: ", nowTime, "\n", "expiry: ", expiry, "\n", "timeToGo: ", timeToGo)

if (timeToGo <= 120) {
console.log("less than 2mins to expiry, attempting refresh...");
Expand All @@ -110,6 +113,7 @@ const LoginComponent:React.FC<LoginComponentProps> = (props) => {
refreshedPromise = overrideRefreshLoginRef.current(oAuthContext.tokenUri);
} else {
refreshedPromise = refreshLogin(oAuthContext, userContext);
console.log("RefreshPromise: ",refreshedPromise)
}

refreshedPromise.then(()=>{
Expand All @@ -119,9 +123,12 @@ const LoginComponent:React.FC<LoginComponentProps> = (props) => {
setRefreshed(true);

if(props.onLoginRefreshed) props.onLoginRefreshed();
console.log(props.onLoginRefreshed)
console.log("Refreshing......")
window.setTimeout(()=>setRefreshed(false), 5000); //show success message for 5s
}).catch(errString=>{
if(props.onLoginCantRefresh) props.onLoginCantRefresh(errString);
console.log("Can't refresh.....")
setRefreshFailed(true);
setRefreshInProgress(false);
updateCountdownHandler();
Expand Down

0 comments on commit 1d10a98

Please sign in to comment.