Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(authentication): authentication log in/log out through Profile section

Calin-Teodor86ccc176e850
diff --git a/lang/main.json b/lang/main.json
index 48dc3f0f8a..1e97bf5520 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -1276,8 +1276,8 @@
"linkToSalesforce": "Link to Salesforce",
"lobbyButtonDisable": "Disable lobby mode",
"lobbyButtonEnable": "Enable lobby mode",
- "login": "Login",
- "logout": "Logout",
+ "login": "Log-in",
+ "logout": "Log-out",
"lowerYourHand": "Lower your hand",
"moreActions": "More actions",
"moreOptions": "More options",
diff --git a/react/features/authentication/middleware.ts b/react/features/authentication/middleware.ts
index 125c2f363c..f5af3138a2 100644
--- a/react/features/authentication/middleware.ts
+++ b/react/features/authentication/middleware.ts
@@ -7,7 +7,6 @@ import {
} from '../base/conference/actionTypes';
import { isRoomValid } from '../base/conference/functions';
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection/actionTypes';
-import { hangup } from '../base/connection/actions';
import { hideDialog } from '../base/dialog/actions';
import { isDialogOpen } from '../base/dialog/functions';
import {
@@ -40,6 +39,7 @@ import { LoginDialog, WaitForOwnerDialog } from './components';
import { getTokenAuthUrl, isTokenAuthEnabled } from './functions';
import logger from './logger';
+
/**
* Middleware that captures connection or conference failed errors and controls
* {@link WaitForOwnerDialog} and {@link LoginDialog}.
@@ -163,33 +163,7 @@ MiddlewareRegistry.register(store => next => action => {
}
case LOGOUT: {
- const { dispatch, getState } = store;
- const state = getState();
- const config = state['features/base/config'];
- const { conference } = store.getState()['features/base/conference'];
-
- if (!conference) {
- break;
- }
-
- dispatch(openLogoutDialog(() => {
- const logoutUrl = config.tokenLogoutUrl;
-
- if (isTokenAuthEnabled(config)
- && config.tokenAuthUrlAutoRedirect
- && state['features/base/jwt'].jwt) {
- // user is logging out remove auto redirect indication
- dispatch(setTokenAuthUrlSuccess(false));
- }
-
- if (logoutUrl) {
- window.location.href = logoutUrl;
-
- return;
- }
-
- conference.room.moderator.logout(() => dispatch(hangup(true)));
- }));
+ _handleLogout(store);
break;
}
@@ -305,3 +279,22 @@ function _handleLogin({ dispatch, getState }: IStore) {
dispatch(openTokenAuthUrl(tokenAuthServiceUrl));
}
+
+/**
+ * Handles logout challenge. Opens logout dialog and hangs up the conference.
+ *
+ * @param {Store} store - The redux store in which the specified {@code action}
+ * is being dispatched.
+ * @param {string} logoutUrl - The url for logging out.
+ * @returns {void}
+ */
+function _handleLogout({ dispatch, getState }: IStore) {
+ const state = getState();
+ const { conference } = state['features/base/conference'];
+
+ if (!conference) {
+ return;
+ }
+
+ dispatch(openLogoutDialog());
+}
diff --git a/react/features/mobile/navigation/components/HeaderNavigationButton.tsx b/react/features/mobile/navigation/components/HeaderNavigationButton.tsx
index 38bf1045fb..ad4dab2683 100644
--- a/react/features/mobile/navigation/components/HeaderNavigationButton.tsx
+++ b/react/features/mobile/navigation/components/HeaderNavigationButton.tsx
@@ -11,6 +11,11 @@ import { navigationStyles } from './styles';
interface IProps {
+ /**
+ * Icon button color.
+ */
+ color?: string;
+
/**
* Is the button disabled?
*/
@@ -42,7 +47,7 @@ interface IProps {
twoActions?: boolean;
}
-const HeaderNavigationButton = ({ disabled, label, onPress, src, style, twoActions }: IProps) => {
+const HeaderNavigationButton = ({ color, disabled, label, onPress, src, style, twoActions }: IProps) => {
let btnStyle;
let labelStyle;
@@ -64,6 +69,7 @@ const HeaderNavigationButton = ({ disabled, label, onPress, src, style, twoActio
{
src ? (
<IconButton
+ color = { color }
onPress = { onPress }
size = { 24 }
src = { src }
diff --git a/react/features/settings/actions.native.ts b/react/features/settings/actions.native.ts
index 532c5d437d..49481f22ee 100644
--- a/react/features/settings/actions.native.ts
+++ b/react/features/settings/actions.native.ts
@@ -1,10 +1,38 @@
+import { Linking } from 'react-native';
+
+import { IStore } from '../app/types';
+import { isTokenAuthEnabled } from '../authentication/functions';
+import { hangup } from '../base/connection/actions.native';
+import { openDialog } from '../base/dialog/actions';
+
+import LogoutDialog from './components/native/LogoutDialog';
+
+
/**
* Opens {@code LogoutDialog}.
*
- * @param {Function} _onLogout - The event in {@code LogoutDialog} that should be
- * enabled on click.
* @returns {Function}
*/
-export function openLogoutDialog(_onLogout: Function): any {
- // this is available only for web at the moment
+export function openLogoutDialog() {
+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
+ const state = getState();
+ const { conference } = state['features/base/conference'];
+
+ const config = state['features/base/config'];
+ const logoutUrl = config.tokenLogoutUrl;
+
+ dispatch(openDialog(LogoutDialog, {
+ onLogout() {
+ if (isTokenAuthEnabled(config)) {
+ if (logoutUrl) {
+ Linking.openURL(logoutUrl);
+ }
+
+ dispatch(hangup(true));
+ } else {
+ conference?.room.moderator.logout(() => dispatch(hangup(true)));
+ }
+ }
+ }));
+ };
}
diff --git a/react/features/settings/actions.web.ts b/react/features/settings/actions.web.ts
index 1b3d1cda43..247ccccec5 100644
--- a/react/features/settings/actions.web.ts
+++ b/react/features/settings/actions.web.ts
@@ -1,16 +1,21 @@
import { batch } from 'react-redux';
import { IStore } from '../app/types';
+import { setTokenAuthUrlSuccess } from '../authentication/actions.web';
+import { isTokenAuthEnabled } from '../authentication/functions';
import {
setFollowMe,
setStartMutedPolicy,
setStartReactionsMuted
} from '../base/conference/actions';
+import { hangup } from '../base/connection/actions.web';
import { openDialog } from '../base/dialog/actions';
import i18next from '../base/i18n/i18next';
+import browser from '../base/lib-jitsi-meet';
import { updateSettings } from '../base/settings/actions';
-import { getLocalVideoTrack } from '../base/tracks/functions.any';
-import { disableKeyboardShortcuts, enableKeyboardShortcuts } from '../keyboard-shortcuts/actions';
+import { getLocalVideoTrack } from '../base/tracks/functions.web';
+import { appendURLHashParam } from '../base/util/uri';
+import { disableKeyboardShortcuts, enableKeyboardShortcuts } from '../keyboard-shortcuts/actions.web';
import { toggleBackgroundEffect } from '../virtual-background/actions';
import virtualBackgroundLogger from '../virtual-background/logger';
@@ -28,15 +33,45 @@ import {
getShortcutsTabProps
} from './functions.web';
+
/**
* Opens {@code LogoutDialog}.
*
- * @param {Function} onLogout - The event in {@code LogoutDialog} that should be
- * enabled on click.
* @returns {Function}
*/
-export function openLogoutDialog(onLogout: Function) {
- return openDialog(LogoutDialog, { onLogout });
+export function openLogoutDialog() {
+ return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
+ const state = getState();
+
+ const config = state['features/base/config'];
+ const logoutUrl = config.tokenLogoutUrl;
+
+ const { conference } = state['features/base/conference'];
+ const { jwt } = state['features/base/jwt'];
+
+ dispatch(openDialog(LogoutDialog, {
+ onLogout() {
+ if (isTokenAuthEnabled(config) && config.tokenAuthUrlAutoRedirect && jwt) {
+
+ // user is logging out remove auto redirect indication
+ dispatch(setTokenAuthUrlSuccess(false));
+ }
+
+ if (logoutUrl && browser.isElectron()) {
+ const url = appendURLHashParam(logoutUrl, 'electron', 'true');
+
+ window.open(url, '_blank');
+ dispatch(hangup(true));
+ } else {
+ if (logoutUrl) {
+ window.location.href = logoutUrl;
+ }
+
+ conference?.room.moderator.logout(() => dispatch(hangup(true)));
+ }
+ }
+ }));
+ };
}
/**
diff --git a/react/features/settings/components/native/LogoutDialog.tsx b/react/features/settings/components/native/LogoutDialog.tsx
new file mode 100644
index 0000000000..ae9abb1287
--- /dev/null
+++ b/react/features/settings/components/native/LogoutDialog.tsx
@@ -0,0 +1,21 @@
+import React from 'react';
+import { WithTranslation } from 'react-i18next';
+
+import ConfirmDialog
+ from '../../../base/dialog/components/native/ConfirmDialog';
+
+interface ILogoutDialogProps extends WithTranslation {
+ onLogout: Function;
+}
+
+
+const LogoutDialog: React.FC<ILogoutDialogProps> = ({ onLogout }: ILogoutDialogProps) => (
+ <ConfirmDialog
+ cancelLabel = 'dialog.Cancel'
+ confirmLabel = 'dialog.Yes'
+ descriptionKey = 'dialog.logoutQuestion'
+ onSubmit = { onLogout } />
+);
+
+export default LogoutDialog;
+
diff --git a/react/features/settings/components/native/ProfileView.tsx b/react/features/settings/components/native/ProfileView.tsx
index 716205f4f2..b6a2534b7f 100644
--- a/react/features/settings/components/native/ProfileView.tsx
+++ b/react/features/settings/components/native/ProfileView.tsx
@@ -1,26 +1,39 @@
-import React, { useCallback, useState } from 'react';
+import { useNavigation } from '@react-navigation/native';
+import React, { useCallback, useLayoutEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ScrollView, Text, View, ViewStyle } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import { IReduxState } from '../../../app/types';
+import { login, logout } from '../../../authentication/actions.native';
import Avatar from '../../../base/avatar/components/Avatar';
+import { IconArrowLeft } from '../../../base/icons/svg';
import JitsiScreen from '../../../base/modal/components/JitsiScreen';
import { getLocalParticipant } from '../../../base/participants/functions';
import { updateSettings } from '../../../base/settings/actions';
+import BaseThemeNative from '../../../base/ui/components/BaseTheme.native';
import Button from '../../../base/ui/components/native/Button';
import Input from '../../../base/ui/components/native/Input';
import { BUTTON_TYPES } from '../../../base/ui/constants.native';
-import { navigate } from '../../../mobile/navigation/components/settings/SettingsNavigationContainerRef';
+import HeaderNavigationButton
+ from '../../../mobile/navigation/components/HeaderNavigationButton';
+import {
+ goBack,
+ navigate
+} from '../../../mobile/navigation/components/settings/SettingsNavigationContainerRef';
import { screen } from '../../../mobile/navigation/routes';
import FormSection from './FormSection';
import { AVATAR_SIZE } from './constants';
import styles from './styles';
-const ProfileView = ({ isInWelcomePage }: { isInWelcomePage?: boolean; }) => {
+
+const ProfileView = ({ isInWelcomePage }: {
+ isInWelcomePage?: boolean;
+}) => {
const { t } = useTranslation();
const dispatch = useDispatch();
+ const navigation = useNavigation();
const { displayName: reduxDisplayName, email: reduxEmail } = useSelector(
(state: IReduxState) => state['features/base/settings']
@@ -30,6 +43,8 @@ const ProfileView = ({ isInWelcomePage }: { isInWelcomePage?: boolean; }) => {
const [ displayName, setDisplayName ] = useState(reduxDisplayName);
const [ email, setEmail ] = useState(reduxEmail);
+ const { authLogin: isAutenticated } = useSelector((state: IReduxState) => state['features/base/conference']);
+
const onDisplayNameChanged = useCallback(newDisplayName => {
setDisplayName(newDisplayName);
}, [ setDisplayName ]);
@@ -48,6 +63,50 @@ const ProfileView = ({ isInWelcomePage }: { isInWelcomePage?: boolean; }) => {
},
[ dispatch, updateSettings, email, displayName ]);
+ const onLogin = useCallback(() => {
+ dispatch(login());
+ }, [ dispatch ]);
+
+ const onLogout = useCallback(() => {
+ dispatch(logout());
+ }, [ dispatch ]);
+
+ const headerLeft = () => (
+ <HeaderNavigationButton
+ color = { BaseThemeNative.palette.link01 }
+ onPress = { goBack }
+ src = { IconArrowLeft }
+ style = { styles.backBtn }
+ twoActions = { true } />
+ );
+
+ const headerRight = () => {
+ if (isAutenticated) {
+ return (
+ <HeaderNavigationButton
+ label = { t('toolbar.logout') }
+ onPress = { onLogout }
+ style = { styles.logBtn }
+ twoActions = { true } />
+ );
+ }
+
+ return (
+ <HeaderNavigationButton
+ label = { t('toolbar.login') }
+ onPress = { onLogin }
+ style = { styles.logBtn }
+ twoActions = { true } />
+ );
+ };
+
+ useLayoutEffect(() => {
+ navigation.setOptions({
+ headerLeft,
+ headerRight: !isInWelcomePage && headerRight
+ });
+ }, [ navigation ]);
+
return (
<JitsiScreen
disableForcedKeyboardDismiss = { true }
diff --git a/react/features/settings/components/native/styles.ts b/react/features/settings/components/native/styles.ts
index a7c59b28cd..0ddc36049c 100644
--- a/react/features/settings/components/native/styles.ts
+++ b/react/features/settings/components/native/styles.ts
@@ -222,5 +222,13 @@ export default {
flexDirection: 'row',
alignItems: 'center',
...BaseTheme.typography.bodyShortBoldLarge
+ },
+
+ logBtn: {
+ marginRight: BaseTheme.spacing[2]
+ },
+
+ backBtn: {
+ marginLeft: BaseTheme.spacing[2]
}
};