ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
125 stars 111 forks source link

Cannot add name and email address to user profile during signup with phone number #71

Closed whenmoon closed 4 years ago

whenmoon commented 4 years ago

During the signup process I need to be able to add a name and email address to the ConnectyCube user profile.

Your docs use this example when not signing up using a phone number and Firebase phone number authentication:

const userProfile = {
  login: "marvin18",
  password: "supersecurepwd",
  email: "awesomeman@gmail.com",
  full_name: "Marvin Simon",
  phone: "47802323143",
  website: "https://dozensofdreams.com",
  tag_list: ["iphone", "apple"],
  custom_data: JSON.stringify({ middle_name: "Bartoleo" }),
};

ConnectyCube.users
  .signup(userProfile)
  .then((user) => {})
  .catch((error) => {});

The docs say that when creating a ConnectyCube account up with a phone number and Firebase, use this code:

const userCredentials = {
    "provider": "firebase_phone",
    "firebase_phone": {"project_id": "..." , "access_token": "..."}
};

ConnectyCube.login(userCredentials)
  .then((user) => {})
  .catch((error) => {});

At the moment I am using this hacky solution that is prone to errors to add a name to a ConnectyCube account during signup with phone number:

const user = await loggedInToFirebase();
  if (user) {
    const accessToken = await user.getIdToken()
    const userCredentials = {
      provider: 'firebase_phone',
      "firebase_phone": {
        "project_id": "xxx",
        "access_token": accessToken
      }
    };
    try {
      const connectyCubeSession = await createConnectyCubeSession();
      const connectyCubeUserProfile = await logInToConnectycube(userCredentials);
      await connectToChat(connectyCubeSession, connectyCubeUserProfile)
      if (connectyCubeUserProfile
        && (connectyCubeUserProfile.full_name === null
          || connectyCubeUserProfile.full_name === "undefined")
        && profileName !== undefined) {
        await addNameToConnectycubeProfile(
          connectyCubeUserProfile.login,
          profileName)
      }

...

export const addNameToConnectycubeProfile = (login, profileName) => {
  const updatedUserProfile = {
    login,
    full_name: profileName,
  };

  return ConnectyCube.users
    .update(updatedUserProfile)
    .then(user => user)
    .catch(error => error);
}

How can I add name and email to ConnectyCube profile during account creation with phone number?

Thanks.

DaveLomber commented 4 years ago

Basically you are correct with the solution.

In terms of phone number authentication - there is no a sign up process, it's only a sign in, which will create a user on the first time a user logs in.

So basically the flow should be like this:

1) sign in with phone number 2) check user's fields - if they are empty -> do another request to user update and set the required name & email

whenmoon commented 4 years ago

Understood Dave thanks. It's actually the same flow when signing in with Firebase.