Skip to content

Commit 33e3ffd

Browse files
committed
realm screen: Give early error when server URL is an email address.
Show an error message when the user tries to enter an email in the server URL input field, even before trying to connect to the server. Fixes: #4058
1 parent b4fdc98 commit 33e3ffd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/start/RealmScreen.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { PureComponent } from 'react';
33
import { ScrollView, Keyboard } from 'react-native';
44
import type { NavigationScreenProp } from 'react-navigation';
55

6+
import { URL as WhatwgURL } from 'react-native-url-polyfill';
67
import { ZulipVersion } from '../utils/zulipVersion';
78
import type { ApiResponseServerSettings, Dispatch } from '../types';
89
import { connect } from '../react-redux';
@@ -53,6 +54,26 @@ class RealmScreen extends PureComponent<Props, State> {
5354

5455
const { dispatch } = this.props;
5556

57+
let parsedRealm;
58+
try {
59+
parsedRealm = new WhatwgURL(realm);
60+
} catch (err) {
61+
this.setState({
62+
progress: false,
63+
error: 'Please enter a valid URL',
64+
});
65+
return;
66+
}
67+
68+
if (parsedRealm.username !== '') {
69+
this.setState({
70+
progress: false,
71+
error:
72+
'Please enter the server URL, not your email. You can enter your credentials in the next screen.',
73+
});
74+
return;
75+
}
76+
5677
try {
5778
const serverSettings: ApiResponseServerSettings = await api.getServerSettings(realm);
5879
dispatch(realmAdd(realm, new ZulipVersion(serverSettings.zulip_version)));

static/translations/messages_en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"Chat": "Chat",
3737
"Sign in with {method}": "Sign in with {method}",
3838
"Cannot connect to server": "Cannot connect to server",
39+
"Please enter a valid URL": "Please enter a valid URL",
40+
"Please enter the server URL, not your email. You can enter your credentials in the next screen.": "Please enter the server URL, not your email. You can enter your credentials in the next screen.",
3941
"Wrong email or password. Try again.": "Wrong email or password. Try again.",
4042
"Wrong username or password. Try again.": "Wrong username or password. Try again.",
4143
"Enter a valid email address": "Enter a valid email address",

0 commit comments

Comments
 (0)