mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-12 16:50:21 +00:00
Merge pull request #1602 from cesanta/device-dashboard
fixed watch() not being called after login
This commit is contained in:
2 files changed
+1378
-206
No files matched your search
+1366
-194
File diff suppressed because it is too large.
Load diff
@@ -312,17 +312,6 @@ const App = function(props) {
|
|||||||
.then(r => setConfig(r))
|
.then(r => setConfig(r))
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
const login = function(u) {
|
|
||||||
document.cookie = `access_token=${u.token};path=/;max-age=3600`;
|
|
||||||
setUser(u.user);
|
|
||||||
return getconfig();
|
|
||||||
};
|
|
||||||
|
|
||||||
const logout = ev => {
|
|
||||||
document.cookie = `access_token=;path=/;max-age=0`;
|
|
||||||
setUser('');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Watch for notifications. As soon as a notification arrives, pass it on
|
// Watch for notifications. As soon as a notification arrives, pass it on
|
||||||
// to all subscribed components
|
// to all subscribed components
|
||||||
const watch = function() {
|
const watch = function() {
|
||||||
@@ -349,13 +338,24 @@ const App = function(props) {
|
|||||||
reconnect();
|
reconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const login = function(u) {
|
||||||
|
document.cookie = `access_token=${u.token};path=/;max-age=3600`;
|
||||||
|
setUser(u.user);
|
||||||
|
watch();
|
||||||
|
return getconfig();
|
||||||
|
};
|
||||||
|
|
||||||
|
const logout = ev => {
|
||||||
|
document.cookie = `access_token=;path=/;max-age=0`;
|
||||||
|
setUser('');
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Called once at init time
|
// Called once at init time
|
||||||
PubSub.subscribe(msg => msg.name == 'config' && getconfig());
|
PubSub.subscribe(msg => msg.name == 'config' && getconfig());
|
||||||
fetch('/api/login', {headers: {Authorization: ''}})
|
fetch('/api/login', {headers: {Authorization: ''}})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(r => login(r))
|
.then(r => login(r))
|
||||||
.then(watch)
|
|
||||||
.catch(err => setUser(''));
|
.catch(err => setUser(''));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user