-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: open login modal on proposalform if session is expired
- Loading branch information
1 parent
eef6622
commit 1fd712a
Showing
7 changed files
with
86 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
import { useState, useEffect, useCallback } from "react"; | ||
import { useState, useEffect, useCallback, useMemo } from "react"; | ||
import * as sel from "src/selectors"; | ||
import { useSelector } from "src/redux"; | ||
|
||
export function useSessionChecker() { | ||
const currentUser = useSelector(sel.currentUser); | ||
const [sessionExpired, setSessionExpired] = useState(false); | ||
|
||
const [sessionExpired, setSessionExpired] = useState(); | ||
const timeout = useMemo(() => { | ||
if (!currentUser) return; | ||
const { sessionmaxage, lastlogintime } = currentUser; | ||
return sessionmaxage * 1000 - (Date.now() / 1000 - lastlogintime); | ||
}, [currentUser]); | ||
|
||
const checkUserSession = useCallback(() => { | ||
if (currentUser && !sessionExpired) { | ||
const { sessionmaxage, lastlogintime } = currentUser; | ||
const expired = sessionmaxage < Date.now() / 1000 - lastlogintime; | ||
setSessionExpired(expired); | ||
} | ||
}, [currentUser, sessionExpired]); | ||
const { sessionmaxage, lastlogintime } = currentUser; | ||
const expired = sessionmaxage < Date.now() / 1000 - lastlogintime; | ||
setSessionExpired(expired); | ||
}, [currentUser]); | ||
|
||
useEffect(() => { | ||
checkUserSession(); | ||
}); | ||
let interval; | ||
if (timeout) { | ||
interval = setInterval(() => { | ||
checkUserSession(); | ||
}, timeout); | ||
} | ||
return () => { | ||
interval && clearInterval(interval); | ||
}; | ||
}, [timeout, checkUserSession]); | ||
|
||
return { sessionExpired, setSessionExpired }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters