Skip to content

Instantly share code, notes, and snippets.

@warodri-sendbird
Created September 2, 2021 15:14
Show Gist options
  • Save warodri-sendbird/e772c5f8f490e09d0c4f9e77f095f112 to your computer and use it in GitHub Desktop.
Save warodri-sendbird/e772c5f8f490e09d0c4f9e77f095f112 to your computer and use it in GitHub Desktop.
const login = user => {
AsyncStorage.setItem(savedUserKey, JSON.stringify(user))
.then(async () => {
try {
setCurrentUser(user);
const authorizationStatus = await messaging().requestPermission();
if (
authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authorizationStatus === messaging.AuthorizationStatus.PROVISIONAL
) {
if (Platform.OS === 'ios') {
const token = await messaging().getAPNSToken();
await sendbird.registerAPNSPushTokenForCurrentUser(token);
} else {
const token = await messaging().getToken();
await sendbird.registerGCMPushTokenForCurrentUser(token);
}
}
} catch (err) {
console.error(err);
}
})
.catch(err => console.error(err));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment