Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created October 18, 2021 13:59
Show Gist options
  • Save hieptl/504da4ca9ee3ff1ebd85488ab999b9f8 to your computer and use it in GitHub Desktop.
Save hieptl/504da4ca9ee3ff1ebd85488ab999b9f8 to your computer and use it in GitHub Desktop.
Login.tsx - Log in to CometChat - Ionic Chat App
...
cometChat.login(firebaseUid, `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`).then(
(User: any) => {
// User loged in successfully.
// save authenticated user to local storage.
localStorage.setItem('auth', JSON.stringify(User));
// save authenticated user to context.
setUser(User);
// hide loading.
setIsLoading(false);
// redirect to home page.
history.push('/');
}, (error: any) => {
console.log(error);
// User login failed, check error and take appropriate action.
setIsLoading(false);
alert(`Your user's name or password is not correct`);
}
);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment