Skip to content

Commit 504d6de

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 1d00cc1 commit 504d6de

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/start/RealmScreen.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ZulipVersion } from '../utils/zulipVersion';
77
import type { ApiResponseServerSettings, Dispatch } from '../types';
88
import { connect } from '../react-redux';
99
import { ErrorMsg, Label, SmartUrlInput, Screen, ZulipButton } from '../common';
10-
import { isValidUrl } from '../utils/url';
10+
import { isValidUrl, tryParseUrl } from '../utils/url';
1111
import * as api from '../api';
1212
import { realmAdd, navigateToAuth } from '../actions';
1313

@@ -45,14 +45,21 @@ class RealmScreen extends PureComponent<Props, State> {
4545
tryRealm = async () => {
4646
const { realm } = this.state;
4747

48+
const parsedRealm = tryParseUrl(realm);
49+
if (!parsedRealm) {
50+
this.setState({ error: 'Please enter a valid URL' });
51+
return;
52+
}
53+
if (parsedRealm.username !== '') {
54+
this.setState({ error: 'Please enter the server URL, not your email' });
55+
return;
56+
}
57+
58+
const { dispatch } = this.props;
4859
this.setState({
49-
realm,
5060
progress: true,
5161
error: null,
5262
});
53-
54-
const { dispatch } = this.props;
55-
5663
try {
5764
const serverSettings: ApiResponseServerSettings = await api.getServerSettings(realm);
5865
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": "Please enter the server URL, not your email",
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)