Created
September 28, 2021 11:49
-
-
Save hieptl/6613e478d1b46f3f46cef65493bd6eb4 to your computer and use it in GitHub Desktop.
login.js - Register New Account - Tinder Clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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