Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created September 28, 2021 11:49
Show Gist options
  • Save hieptl/6613e478d1b46f3f46cef65493bd6eb4 to your computer and use it in GitHub Desktop.
Save hieptl/6613e478d1b46f3f46cef65493bd6eb4 to your computer and use it in GitHub Desktop.
login.js - Register New Account - Tinder Clone
const registerNewAccount = ({ avatar, email, password, fullname, age, gender }) => {
showLoading();
const userUuid = uuid.v4();
const form = new FormData();
form.append("avatar", avatar);
form.append("email", email);
form.append("password", password);
form.append("age", age);
form.append("gender", gender);
form.append("ccUid", userUuid);
form.append("fullname", fullname);
axios
.post("/users/create", form)
.then((res) => {
if (res && res.data && res.data.message) {
alert(res.data.message);
} else if (res && res.data && res.data.insertId) {
const user = new CometChat.User(userUuid);
user.setName(fullname);
user.setAvatar(`${window.location.origin}${res.data.avatar}`);
const appSetting = new CometChat.AppSettingsBuilder()
.subscribePresenceForAllUsers()
.setRegion(config.CometChatRegion)
.build();
CometChat.init(config.CometChatAppId, appSetting).then(
() => {
CometChat.createUser(user, config.CometChatAuthKey).then(
(user) => {
alert("You account has been created successfully");
},
(error) => {
}
);
},
(error) => {
// Check the reason for error and take appropriate action.
}
);
hideLoading();
resetSignUpForm();
hideSignUp();
} else {
alert("Cannot create your account. Please try again");
}
})
.catch((error) => {
hideLoading();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment