Hook for maintaining active user sessions
The useKeepSessionAlive
hook provides functionality to extend the current user session without requiring re-authentication.
import { useKeepSessionAlive } from "@getpara/react-sdk@alpha";
function SessionManager() {
const { keepSessionAlive, keepSessionAliveAsync, isPending } = useKeepSessionAlive();
const [lastRefresh, setLastRefresh] = useState<Date | null>(null);
const handleKeepAlive = async () => {
try {
const success = await keepSessionAliveAsync();
if (success) {
setLastRefresh(new Date());
console.log("Session extended successfully");
}
} catch (err) {
console.error("Session extension error:", err);
}
};
return (
<button
onClick={handleKeepAlive}
disabled={isPending}
>
{isPending ? "Extending..." : "Extend Session"}
</button>
);
}