Check username taken
This commit is contained in:
		
							parent
							
								
									6039002ed5
								
							
						
					
					
						commit
						7bd1c6e115
					
				
					 4 changed files with 16 additions and 5 deletions
				
			
		|  | @ -47,7 +47,6 @@ import ( | ||||||
| 		purge accounts that were not logged into in X | 		purge accounts that were not logged into in X | ||||||
| 		sync subscription display name | 		sync subscription display name | ||||||
| 		store users | 		store users | ||||||
| 		signup: check unique user |  | ||||||
| 		Pages: | 		Pages: | ||||||
| 		- Home | 		- Home | ||||||
| 		- Password reset | 		- Password reset | ||||||
|  |  | ||||||
|  | @ -160,6 +160,9 @@ class Api { | ||||||
|             method: "POST", |             method: "POST", | ||||||
|             body: body |             body: body | ||||||
|         }); |         }); | ||||||
|  |         if (response.status === 409) { | ||||||
|  |             throw new UsernameTakenError(username) | ||||||
|  |         } | ||||||
|         if (response.status !== 200) { |         if (response.status !== 200) { | ||||||
|             throw new Error(`Unexpected server response ${response.status}`); |             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(); | const api = new Api(); | ||||||
| export default api; | export default api; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import * as React from 'react'; | ||||||
| import TextField from "@mui/material/TextField"; | import TextField from "@mui/material/TextField"; | ||||||
| import Button from "@mui/material/Button"; | import Button from "@mui/material/Button"; | ||||||
| import Box from "@mui/material/Box"; | import Box from "@mui/material/Box"; | ||||||
| import api from "../app/Api"; | import api, {UsernameTakenError} from "../app/Api"; | ||||||
| import routes from "./routes"; | import routes from "./routes"; | ||||||
| import session from "../app/Session"; | import session from "../app/Session"; | ||||||
| import Typography from "@mui/material/Typography"; | import Typography from "@mui/material/Typography"; | ||||||
|  | @ -34,7 +34,9 @@ const Signup = () => { | ||||||
|             } |             } | ||||||
|         } catch (e) { |         } catch (e) { | ||||||
|             console.log(`[Signup] Signup for user ${user.username} failed`, 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); |                 setError(e.message); | ||||||
|             } else { |             } else { | ||||||
|                 setError(t("Unknown error. Check logs for details.")) |                 setError(t("Unknown error. Check logs for details.")) | ||||||
|  |  | ||||||
|  | @ -14,8 +14,8 @@ const SiteLayout = (props) => { | ||||||
|                         <li><NavLink to={routes.home} activeStyle>Features</NavLink></li> |                         <li><NavLink to={routes.home} activeStyle>Features</NavLink></li> | ||||||
|                         <li><NavLink to={routes.pricing} activeStyle>Pricing</NavLink></li> |                         <li><NavLink to={routes.pricing} activeStyle>Pricing</NavLink></li> | ||||||
|                         <li><NavLink to="/docs" reloadDocument={true} activeStyle>Docs</NavLink></li> |                         <li><NavLink to="/docs" reloadDocument={true} activeStyle>Docs</NavLink></li> | ||||||
|                         {!session.exists() && <li><NavLink to={routes.signup} activeStyle>Sign up</NavLink></li>} |                         {config.enableSignup && !session.exists() && <li><NavLink to={routes.signup} activeStyle>Sign up</NavLink></li>} | ||||||
|                         {!session.exists() && <li><NavLink to={routes.login} activeStyle>Login</NavLink></li>} |                         {config.enableLogin && !session.exists() && <li><NavLink to={routes.login} activeStyle>Login</NavLink></li>} | ||||||
|                         <li><NavLink to={routes.app} activeStyle>Open app</NavLink></li> |                         <li><NavLink to={routes.app} activeStyle>Open app</NavLink></li> | ||||||
|                     </ol> |                     </ol> | ||||||
|                 </div> |                 </div> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue