login check effect

This commit is contained in:
ntr committed 2022-09-18 21:04:01 +10:00
1 parent 3bd8691ebf
commit f6f03730e3
5 files changed
+21 -3

No files matched your search

+6 -2
View File
@@ -1,5 +1,6 @@
import { h } from 'preact';
import { route } from 'preact-router';
import { useEffect } from 'preact/hooks';
import { useSelector, useDispatch } from 'react-redux'
import http from './../http';
@@ -13,11 +14,14 @@ const Header = () => {
const dispatch = useDispatch()
const user = useSelector((state: State) => state.user);
useEffect(() => {
if (!user) route('/login');
}, [user])
async function logoutClick(e) {
e.preventDefault();
await http.postLogout();
route('/login');
dispatch(userState.actions.set(null));
window.location.reload();
}
const nav = () => (
+5
View File
@@ -38,6 +38,10 @@ export default function createSocket(dispatch) {
send(['Offers', {}]);
}
function sendWants() {
send(['Wants', {}]);
}
function sendAcpOffers() {
send(['AcpOffers', {}]);
}
@@ -109,6 +113,7 @@ export default function createSocket(dispatch) {
sendPing();
sendAcpOffers();
sendOffers();
sendWants();
}
function onError(event) {