Adding login status checking

This commit is contained in:
Piotr Pawałowski 2020-11-12 12:32:27 +01:00
parent 7e850c979b
commit 9299fe087f
3 changed files with 44 additions and 3 deletions

View file

@ -534,6 +534,14 @@ export default class RoomClient
window.open(`/auth/logout?peerId=${this._peerId}&roomId=${roomId}`, 'logoutWindow');
}
setLoggedIn(loggedIn)
{
logger.debug('setLoggedIn() | [loggedIn: "%s"]', loggedIn);
store.dispatch(meActions.loggedIn(loggedIn));
}
receiveLoginChildWindow(data)
{
logger.debug('receiveFromChildWindow() | [data:"%o"]', data);

View file

@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react';
import Logger from '../Logger';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import { withRoomContext } from '../RoomContext';
@ -126,6 +127,8 @@ const styles = (theme) =>
});
const logger = new Logger('JoinDialog');
const DialogTitle = withStyles((theme) => ({
root :
{
@ -174,9 +177,7 @@ const JoinDialog = ({
displayName = displayName.trimLeft();
const authTypeDefault = (loggedIn) ? 'auth' : 'guest';
const [ authType, setAuthType ] = useState(authTypeDefault);
const [ authType, setAuthType ] = useState((loggedIn) ? 'auth' : 'guest');
const [ roomId, setRoomId ] = useState(
decodeURIComponent(location.pathname.slice(1)) ||
@ -286,6 +287,25 @@ const JoinDialog = ({
}
};
fetch('/auth/check_login_status', {
credentials : 'include',
method : 'GET',
cache : 'no-cache',
redirect : 'follow',
referrerPolicy : 'no-referrer' })
.then((response) => response.json())
.then((json) =>
{
if (json.loggedIn)
{
roomClient.setLoggedIn(json.loggedIn);
}
})
.catch((error) =>
{
logger.error('Error checking login status', error);
});
return (
<div className={classes.root}>
<Dialog

View file

@ -456,6 +456,19 @@ async function setupAuth()
}
);
app.get('/auth/check_login_status', (req, res) =>
{
let loggedIn = false;
if (Boolean(req.session.passport) &&
Boolean(req.session.passport.user))
{
loggedIn = true;
}
res.send({ loggedIn: loggedIn });
});
// logout
app.get('/auth/logout', (req, res) =>
{