1+ import { Loading } from '@/Loading'
12import { Logo } from '@/Logo'
23import { Sheet } from '@mui/joy'
34import {
78 Button ,
89} from '@mui/joy'
910import React from 'react'
10- import { loginWithRedirect } from '@/utils/msal'
11+ import { initializeMsal , loginSilently , loginWithRedirect } from '@/utils/msal'
1112import { setTitle } from '@/utils/dom'
12- import { WithNavigate } from '@/utils/navigation'
13+ import { NavigationPaths , WithNavigate } from '@/utils/navigation'
1314import { connect } from 'react-redux'
1415import { AppDispatch } from '@/store/store'
1516import { pushStatus } from '@/store/statusSlice'
@@ -19,9 +20,25 @@ type LoginViewProps = WithNavigate & {
1920 pushStatus : ( message : string , severity : StatusSeverity , timeout ?: number ) => void
2021}
2122
22- class LoginViewImpl extends React . Component < LoginViewProps > {
23- componentDidMount ( ) : void {
23+ type LoginViewState = {
24+ authReady : boolean
25+ }
26+
27+ class LoginViewImpl extends React . Component < LoginViewProps , LoginViewState > {
28+ constructor ( props : LoginViewProps ) {
29+ super ( props )
30+ this . state = { authReady : false }
31+ }
32+
33+ async componentDidMount ( ) : Promise < void > {
2434 setTitle ( 'Login' )
35+ await initializeMsal ( )
36+ const silentOk = await loginSilently ( )
37+ if ( silentOk ) {
38+ this . props . navigate ( NavigationPaths . HomeView ( ) )
39+ return
40+ }
41+ this . setState ( { authReady : true } )
2542 }
2643
2744 private handleLogin = async ( ) => {
@@ -33,6 +50,10 @@ class LoginViewImpl extends React.Component<LoginViewProps> {
3350 }
3451
3552 render ( ) : React . ReactNode {
53+ if ( ! this . state . authReady ) {
54+ return < Loading />
55+ }
56+
3657 return (
3758 < Container
3859 component = 'main'
0 commit comments