0

I created an app with react and firebase authentication I wish that during registration / login, I only need to enter the "username".

"username"@mydefaultdomain.com

@observer
class Register extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      name: "",
      email: "",
      password: "",
      verifyPassword: "",
      isEmailInvalid: true
    };
  }
KENdi
  • 7,576
  • 2
  • 16
  • 31
fn2505
  • 1
  • Adding a fake domain at the end of a username is not a good way to achieve username authentication. It is recommended to ask the user for both their username and email address and use the email to sign in. Check out [this question](https://stackoverflow.com/questions/37467492/how-to-provide-user-login-with-a-username-and-not-an-email). – KeroppiMomo Jun 06 '19 at 13:19

1 Answers1

1

Ok so basically you want to join two string in which first part is variable. That can be done by using javascript predefined function "concat()".

 var str1 = "Hello";
 var str2 = str1.concat("@gmail.com");
SIDDHARTH VARSHNEY
  • 521
  • 1
  • 6
  • 17
  • Why not use `str1 + '@gmail.com'`? [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat) actually recommends using the `+` operator instead. – KeroppiMomo Jun 06 '19 at 13:22
  • Thanks guys for the help. So @KeroppiMomo , where should I add that line of code? – fn2505 Jun 07 '19 at 08:00
  • @fn2505 wherever you are calling that state variable implement it there. – SIDDHARTH VARSHNEY Jun 07 '19 at 08:27
  • @SIDDHARTH VARSHNEY forgive me I'm still learning. Should I implement it in register.js near this.state = { name: "", email: "",? sorry for bad english – fn2505 Jun 07 '19 at 11:29
  • https://medium.com/capital-one-tech/how-to-work-with-forms-inputs-and-events-in-react-c337171b923b Check out this link to lean how onChange events are used to set states – SIDDHARTH VARSHNEY Jun 08 '19 at 12:47