@@ -56,11 +56,8 @@ function Homeserver({ onChange }) {
5656 const setupHsConfig = async ( servername ) => {
5757 setProcess ( { isLoading : true , message : 'Looking for homeserver...' } ) ;
5858 let baseUrl = null ;
59- try {
60- baseUrl = await getBaseUrl ( servername ) ;
61- } catch ( e ) {
62- baseUrl = e . message ;
63- }
59+ baseUrl = await getBaseUrl ( servername ) ;
60+
6461 if ( searchingHs !== servername ) return ;
6562 setProcess ( { isLoading : true , message : `Connecting to ${ baseUrl } ...` } ) ;
6663 const tempClient = auth . createTemporaryClient ( baseUrl ) ;
@@ -175,31 +172,38 @@ function Login({ loginFlow, baseUrl }) {
175172
176173 const validator = ( values ) => {
177174 const errors = { } ;
178- if ( typeIndex === 0 && values . username . length > 0 && values . username . indexOf ( ':' ) > - 1 ) {
179- errors . username = 'Username must contain local-part only' ;
180- }
181175 if ( typeIndex === 1 && values . email . length > 0 && ! isValidInput ( values . email , EMAIL_REGEX ) ) {
182176 errors . email = BAD_EMAIL_ERROR ;
183177 }
184178 return errors ;
185179 } ;
186- const submitter = ( values , actions ) => auth . login (
187- baseUrl ,
188- typeIndex === 0 ? normalizeUsername ( values . username ) : undefined ,
189- typeIndex === 1 ? values . email : undefined ,
190- values . password ,
191- ) . then ( ( ) => {
192- actions . setSubmitting ( true ) ;
193- window . location . reload ( ) ;
194- } ) . catch ( ( error ) => {
195- let msg = error . message ;
196- if ( msg === 'Unknown message' ) msg = 'Please check your credentials' ;
197- actions . setErrors ( {
198- password : msg === 'Invalid password' ? msg : undefined ,
199- other : msg !== 'Invalid password' ? msg : undefined ,
180+ const submitter = async ( values , actions ) => {
181+ let userBaseUrl = baseUrl ;
182+ let { username } = values ;
183+ const mxIdMatch = username . match ( / ^ @ ( .+ ) : ( .+ \. .+ ) $ / ) ;
184+ if ( typeIndex === 0 && mxIdMatch ) {
185+ [ , username , userBaseUrl ] = mxIdMatch ;
186+ userBaseUrl = await getBaseUrl ( userBaseUrl ) ;
187+ }
188+
189+ return auth . login (
190+ userBaseUrl ,
191+ typeIndex === 0 ? normalizeUsername ( username ) : undefined ,
192+ typeIndex === 1 ? values . email : undefined ,
193+ values . password ,
194+ ) . then ( ( ) => {
195+ actions . setSubmitting ( true ) ;
196+ window . location . reload ( ) ;
197+ } ) . catch ( ( error ) => {
198+ let msg = error . message ;
199+ if ( msg === 'Unknown message' ) msg = 'Please check your credentials' ;
200+ actions . setErrors ( {
201+ password : msg === 'Invalid password' ? msg : undefined ,
202+ other : msg !== 'Invalid password' ? msg : undefined ,
203+ } ) ;
204+ actions . setSubmitting ( false ) ;
200205 } ) ;
201- actions . setSubmitting ( false ) ;
202- } ) ;
206+ } ;
203207
204208 return (
205209 < >
0 commit comments