Expo-Notifications giving firebase authentication error

  Kiến thức lập trình

I’m trying to implement push notifications using expo-notifications:

async function registerForPushNotificationsAsync() {
  let token;
  if (Devices.isDevice) {
    const { status: existingStatus } = await Notifications.getPermissionsAsync();
    console.log(existingStatus);
    
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Notifications.requestPermissionsAsync();
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      alert('Failed to get push token for push notification!');
      return;
    }
    try {
      token = (await Notifications.getExpoPushTokenAsync()).data;
      console.log('Expo Push Token:', token);
    } catch (error) {
      console.error('Error fetching push token:', error);
      alert('Failed to get push token for push notification!');
      return;
    }
    
  } else {
    alert('Must use physical device for Push Notifications');
  }

  if (Platform.OS === 'android') {
    await Notifications.setNotificationChannelAsync('default', {
      name: 'default',
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: '#FF231F7C',
    });
  }

  return token;
}

The status is getting logged in the console as ‘granted’, but the token is not getting generated and I’m getting this error :
Error fetching push token: [Error: Fetching the token failed: java.util.concurrent.ExecutionException: java.io.IOException: FIS_AUTH_ERROR]

All the authentication is working properly and the users are able to login. I don’t get what the problem is. Could someone explain

I also tried native-notify as an alternative, but it worked only in expo go. I also tried changing the Devices to Constants, but it gave me an alert to use a physical device even though I was using one

New contributor

Samarth Shetty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT