1414// You should have received a copy of the GNU Lesser General Public License along
1515// with Greenlight; if not, see <http://www.gnu.org/licenses/>.
1616
17- import React , { useEffect } from 'react' ;
18- import { Container } from 'react-bootstrap' ;
19- import { Outlet , useLocation } from 'react-router-dom' ;
17+ import React , { useEffect , useRef } from 'react' ;
18+ import { Container , Form , Spinner } from 'react-bootstrap' ;
19+ import {
20+ Outlet , useLocation , useNavigate , useSearchParams ,
21+ } from 'react-router-dom' ;
2022import { useTranslation } from 'react-i18next' ;
2123import { ToastContainer , toast } from 'react-toastify' ;
2224import Header from './components/shared_components/Header' ;
2325import { useAuth } from './contexts/auth/AuthProvider' ;
2426import Footer from './components/shared_components/Footer' ;
2527import useSiteSetting from './hooks/queries/site_settings/useSiteSetting' ;
2628import Title from './components/shared_components/utilities/Title' ;
29+ import useEnv from './hooks/queries/env/useEnv' ;
2730
2831export default function App ( ) {
2932 const currentUser = useAuth ( ) ;
3033 const location = useLocation ( ) ;
34+ const navigate = useNavigate ( ) ;
35+ const [ searchParams ] = useSearchParams ( ) ;
36+ const { data : env } = useEnv ( ) ;
37+ const autoSignIn = searchParams . get ( 'sso' ) ;
38+ const formRef = useRef ( null ) ;
3139
3240 // check for the maintenance banner
3341 const maintenanceBanner = useSiteSetting ( [ 'Maintenance' ] ) ;
@@ -50,6 +58,18 @@ export default function App() {
5058 }
5159 } , [ maintenanceBanner . data ] ) ;
5260
61+ // Handle sso login through parameter
62+ useEffect ( ( ) => {
63+ if ( ! env || currentUser . signed_in || ! autoSignIn ) return ;
64+
65+ if ( env . EXTERNAL_AUTH ) {
66+ // eslint-disable-next-line no-unused-expressions
67+ formRef . current ?. requestSubmit ?. ( ) || formRef . current ?. submit ( ) ;
68+ } else {
69+ navigate ( '/signin' , { replace : true } ) ;
70+ }
71+ } , [ autoSignIn , env , formRef . current ] ) ;
72+
5373 // Pages that do not need a header: SignIn, SignUp and JoinMeeting (if the user is not signed in)
5474 const homePage = location . pathname === '/' ;
5575 const pageHeight = ( homePage || currentUser . signed_in ) ? 'regular-height' : 'no-header-height' ;
@@ -72,16 +92,32 @@ export default function App() {
7292 return (
7393 < >
7494 < Title > BigBlueButton</ Title >
75- { ( homePage || currentUser . signed_in ) && < Header /> }
76- < Container className = { pageHeight } >
77- < Outlet />
78- </ Container >
79- < ToastContainer
80- position = "bottom-right"
81- newestOnTop
82- autoClose = { 3000 }
83- />
84- < Footer />
95+ { autoSignIn
96+ ? (
97+ < Container fluid className = "d-flex vh-100 justify-content-center align-items-center" >
98+ < Spinner animation = "border" role = "status" >
99+ < span className = "visually-hidden" > Signing you in…</ span >
100+ </ Spinner >
101+
102+ < Form id = "sso-form" ref = { formRef } action = { process . env . OMNIAUTH_PATH } method = "POST" data-turbo = "false" className = "d-none" >
103+ < input type = "hidden" name = "authenticity_token" value = { document . querySelector ( 'meta[name="csrf-token"]' ) . content } />
104+ < input type = "hidden" name = "current_provider" value = { env ?. CURRENT_PROVIDER } />
105+ </ Form >
106+ </ Container >
107+ ) : (
108+ < >
109+ { ( homePage || currentUser . signed_in ) && < Header /> }
110+ < Container className = { pageHeight } >
111+ < Outlet />
112+ </ Container >
113+ < ToastContainer
114+ position = "bottom-right"
115+ newestOnTop
116+ autoClose = { 3000 }
117+ />
118+ < Footer />
119+ </ >
120+ ) }
85121 </ >
86122 ) ;
87123}
0 commit comments