diff --git a/server/server.go b/server/server.go index 2484ba5e..1c4ee596 100644 --- a/server/server.go +++ b/server/server.go @@ -47,7 +47,6 @@ import ( purge accounts that were not logged into in X sync subscription display name store users - signup: check unique user Pages: - Home - Password reset diff --git a/web/src/app/Api.js b/web/src/app/Api.js index 381b1989..b3b383cf 100644 --- a/web/src/app/Api.js +++ b/web/src/app/Api.js @@ -160,6 +160,9 @@ class Api { method: "POST", body: body }); + if (response.status === 409) { + throw new UsernameTakenError(username) + } if (response.status !== 200) { throw new Error(`Unexpected server response ${response.status}`); } @@ -250,5 +253,12 @@ class Api { } } +export class UsernameTakenError extends Error { + constructor(username) { + super(); + this.username = username; + } +} + const api = new Api(); export default api; diff --git a/web/src/components/Signup.js b/web/src/components/Signup.js index eaf7ef08..5956ed34 100644 --- a/web/src/components/Signup.js +++ b/web/src/components/Signup.js @@ -2,7 +2,7 @@ import * as React from 'react'; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import Box from "@mui/material/Box"; -import api from "../app/Api"; +import api, {UsernameTakenError} from "../app/Api"; import routes from "./routes"; import session from "../app/Session"; import Typography from "@mui/material/Typography"; @@ -34,7 +34,9 @@ const Signup = () => { } } catch (e) { console.log(`[Signup] Signup for user ${user.username} failed`, e); - if (e && e.message) { + if ((e instanceof UsernameTakenError)) { + setError(t("Username {{username}} is already taken", { username: e.username })); + } else if (e.message) { setError(e.message); } else { setError(t("Unknown error. Check logs for details.")) diff --git a/web/src/components/SiteLayout.js b/web/src/components/SiteLayout.js index d6e050ca..fd3fa882 100644 --- a/web/src/components/SiteLayout.js +++ b/web/src/components/SiteLayout.js @@ -14,8 +14,8 @@ const SiteLayout = (props) => {