@@ -34,14 +34,9 @@ const Login: React.FC = () => {
3434 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
3535 const [ authMethods , setAuthMethods ] = useState < string [ ] > ( [ ] ) ;
3636 const [ usernamePasswordMethod , setUsernamePasswordMethod ] = useState < string > ( '' ) ;
37- const [ apiBaseUrl , setApiBaseUrl ] = useState < string > ( '' ) ;
3837
3938 useEffect ( ( ) => {
40- // Initialize API base URL
4139 getBaseUrl ( ) . then ( ( baseUrl ) => {
42- setApiBaseUrl ( baseUrl ) ;
43-
44- // Fetch auth config
4540 axios . get ( `${ baseUrl } /api/auth/config` ) . then ( ( response ) => {
4641 const usernamePasswordMethod = response . data . usernamePasswordMethod ;
4742 const otherMethods = response . data . otherMethods ;
@@ -51,7 +46,7 @@ const Login: React.FC = () => {
5146
5247 // Automatically login if only one non-username/password method is enabled
5348 if ( ! usernamePasswordMethod && otherMethods . length === 1 ) {
54- handleAuthMethodLogin ( otherMethods [ 0 ] , baseUrl ) ;
49+ handleAuthMethodLogin ( otherMethods [ 0 ] ) ;
5550 }
5651 } ) ;
5752 } ) ;
@@ -63,37 +58,40 @@ const Login: React.FC = () => {
6358 ) ;
6459 }
6560
66- function handleAuthMethodLogin ( authMethod : string , baseUrl ?: string ) : void {
67- const url = baseUrl || apiBaseUrl ;
68- window . location . href = `${ url } /api/auth/${ authMethod } ` ;
61+ function handleAuthMethodLogin ( authMethod : string ) : void {
62+ getBaseUrl ( ) . then ( ( baseUrl ) => {
63+ window . location . href = `${ baseUrl } /api/auth/${ authMethod } ` ;
64+ } ) ;
6965 }
7066
7167 function handleSubmit ( event : FormEvent ) : void {
7268 event . preventDefault ( ) ;
7369 setIsLoading ( true ) ;
7470
75- const loginUrl = `${ apiBaseUrl } /api/auth/login` ;
76- axios
77- . post < LoginResponse > ( loginUrl , { username, password } , getAxiosConfig ( ) )
78- . then ( ( ) => {
79- window . sessionStorage . setItem ( 'git.proxy.login' , 'success' ) ;
80- setMessage ( 'Success!' ) ;
81- setSuccess ( true ) ;
82- authContext . refreshUser ( ) . then ( ( ) => navigate ( 0 ) ) ;
83- } )
84- . catch ( ( error : AxiosError ) => {
85- if ( error . response ?. status === 307 ) {
71+ getBaseUrl ( ) . then ( ( baseUrl ) => {
72+ const loginUrl = `${ baseUrl } /api/auth/login` ;
73+ axios
74+ . post < LoginResponse > ( loginUrl , { username, password } , getAxiosConfig ( ) )
75+ . then ( ( ) => {
8676 window . sessionStorage . setItem ( 'git.proxy.login' , 'success' ) ;
87- setGitAccountError ( true ) ;
88- } else if ( error . response ?. status === 403 ) {
89- setMessage ( processAuthError ( error , false ) ) ;
90- } else {
91- setMessage ( 'You entered an invalid username or password...' ) ;
92- }
93- } )
94- . finally ( ( ) => {
95- setIsLoading ( false ) ;
96- } ) ;
77+ setMessage ( 'Success!' ) ;
78+ setSuccess ( true ) ;
79+ authContext . refreshUser ( ) . then ( ( ) => navigate ( 0 ) ) ;
80+ } )
81+ . catch ( ( error : AxiosError ) => {
82+ if ( error . response ?. status === 307 ) {
83+ window . sessionStorage . setItem ( 'git.proxy.login' , 'success' ) ;
84+ setGitAccountError ( true ) ;
85+ } else if ( error . response ?. status === 403 ) {
86+ setMessage ( processAuthError ( error , false ) ) ;
87+ } else {
88+ setMessage ( 'You entered an invalid username or password...' ) ;
89+ }
90+ } )
91+ . finally ( ( ) => {
92+ setIsLoading ( false ) ;
93+ } ) ;
94+ } ) ;
9795 }
9896
9997 if ( gitAccountError ) {
0 commit comments