@@ -4,14 +4,17 @@ import { AnyAction } from 'redux';
44
55import { IStore } from '../../app/types' ;
66import { loginWithPopup } from '../../authentication/actions' ;
7+ import LoginQuestionDialog from '../../authentication/components/web/LoginQuestionDialog' ;
78import { getTokenAuthUrl , isTokenAuthInline } from '../../authentication/functions' ;
89import { isVpaasMeeting } from '../../jaas/functions' ;
910import { hideNotification , showNotification } from '../../notifications/actions' ;
1011import { NOTIFICATION_TIMEOUT_TYPE , NOTIFICATION_TYPE } from '../../notifications/constants' ;
1112import { authStatusChanged } from '../conference/actions.any' ;
1213import { getCurrentConference } from '../conference/functions' ;
1314import { SET_CONFIG } from '../config/actionTypes' ;
14- import { CONNECTION_ESTABLISHED , CONNECTION_RESUMING , SET_LOCATION_URL } from '../connection/actionTypes' ;
15+ import { CONNECTION_ESTABLISHED , CONNECTION_TOKEN_EXPIRED , SET_LOCATION_URL } from '../connection/actionTypes' ;
16+ import { openDialog } from '../dialog/actions' ;
17+ import { browser } from '../lib-jitsi-meet' ;
1518import { participantUpdated } from '../participants/actions' ;
1619import { getLocalParticipant } from '../participants/functions' ;
1720import { IParticipant } from '../participants/types' ;
@@ -55,12 +58,11 @@ MiddlewareRegistry.register(store => next => action => {
5558 // XXX The JSON Web Token (JWT) is not the only piece of state that we
5659 // have decided to store in the feature jwt
5760 return _setConfigOrLocationURL ( store , next , action ) ;
58- case CONNECTION_RESUMING : {
61+ case CONNECTION_TOKEN_EXPIRED : {
5962 const jwt = state [ 'features/base/jwt' ] . jwt ;
6063 const refreshToken = state [ 'features/base/jwt' ] . refreshToken ;
6164
62- if ( typeof APP !== 'undefined'
63- && jwt && isTokenAuthInline ( state [ 'features/base/config' ] )
65+ if ( typeof APP !== 'undefined' && jwt
6466 && validateJwt ( jwt ) . find ( ( e : any ) => e . key === JWT_VALIDATION_ERRORS . TOKEN_EXPIRED ) ) {
6567 const { connection, locationURL = { href : '' } as URL } = state [ 'features/base/connection' ] ;
6668 const { tenant } = parseURIString ( locationURL . href ) || { } ;
@@ -92,23 +94,39 @@ MiddlewareRegistry.register(store => next => action => {
9294 customActionHandler : [ ( ) => {
9395 store . dispatch ( hideNotification ( PROMPT_LOGIN_NOTIFICATION_ID ) ) ;
9496
95- // Use refresh token if available, otherwise fall back to silent login
96- loginWithPopup ( url )
97- . then ( ( result : { accessToken : string ; idToken : string ; refreshToken ?: string ; } ) => {
98- // @ts -ignore
99- const token : string = result . accessToken ;
100- const idToken : string = result . idToken ;
101- const newRefreshToken : string | undefined = result . refreshToken ;
102-
103- // @ts -ignore
104- dispatch ( setJWT ( token , idToken , newRefreshToken || refreshToken ) ) ;
105-
106- connection ?. refreshToken ( token )
107- . catch ( ( err : any ) => {
108- dispatch ( setJWT ( ) ) ;
109- logger . error ( err ) ;
110- } ) ;
111- } ) . catch ( logger . error ) ;
97+ if ( isTokenAuthInline ( state [ 'features/base/config' ] ) ) {
98+ // Use refresh token if available, otherwise fall back to silent login
99+ loginWithPopup ( url )
100+ . then ( ( result : { accessToken : string ; idToken : string ; refreshToken ?: string ; } ) => {
101+ // @ts -ignore
102+ const token : string = result . accessToken ;
103+ const idToken : string = result . idToken ;
104+ const newRefreshToken : string | undefined = result . refreshToken ;
105+
106+ // @ts -ignore
107+ dispatch ( setJWT ( token , idToken , newRefreshToken || refreshToken ) ) ;
108+
109+ connection ?. refreshToken ( token )
110+ . catch ( ( err : any ) => {
111+ dispatch ( setJWT ( ) ) ;
112+ logger . error ( err ) ;
113+ } ) ;
114+ } ) . catch ( logger . error ) ;
115+ } else {
116+ dispatch ( openDialog ( 'LoginQuestionDialog' , LoginQuestionDialog , {
117+ handler : ( ) => {
118+ // Give time for the dialog to close.
119+ setTimeout ( ( ) => {
120+ if ( browser . isElectron ( ) ) {
121+ window . open ( url , '_blank' ) ;
122+ } else {
123+ window . location . href = url ;
124+ }
125+ } , 500 ) ;
126+ }
127+ } ) ) ;
128+ }
129+
112130 } ] ,
113131 appearance : NOTIFICATION_TYPE . ERROR
114132 } , NOTIFICATION_TIMEOUT_TYPE . STICKY ) ) ;
0 commit comments