login check effect
This commit is contained in:
1 parent
3bd8691ebf
commit
f6f03730e3
5 files changed
+21
-3
No files matched your search
@@ -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 = () => (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user