fixed push notifications and auth modified
This commit is contained in:
@@ -7,11 +7,20 @@ import {
|
||||
onMessage,
|
||||
onNotificationOpenedApp,
|
||||
getInitialNotification,
|
||||
setBackgroundMessageHandler,
|
||||
} from '@react-native-firebase/messaging';
|
||||
import { registerDeviceToken, listenForTokenRefresh } from '@/services/notifications';
|
||||
import { registerDeviceToken, listenForTokenRefresh, displayLocalNotification } from '@/services/notifications';
|
||||
import { AuthProvider, useAuth } from "@/context/AuthContext";
|
||||
import Toast from 'react-native-toast-message';
|
||||
|
||||
// Registered at module scope so it's installed as soon as this entry file
|
||||
// loads, which is required for it to fire while the app is backgrounded/killed.
|
||||
setBackgroundMessageHandler(getMessaging(), async (remoteMessage) => {
|
||||
const title = remoteMessage.data?.title as string | undefined;
|
||||
const body = remoteMessage.data?.body as string | undefined;
|
||||
await displayLocalNotification(title, body);
|
||||
});
|
||||
|
||||
function NotificationSetup() {
|
||||
const { user, loading } = useAuth();
|
||||
|
||||
@@ -27,7 +36,8 @@ function NotificationSetup() {
|
||||
console.log('Foreground notification:', msg);
|
||||
Toast.show({
|
||||
type: 'info',
|
||||
text1: msg.notification?.title ?? 'New Notification',
|
||||
text1: (msg.data?.title as string | undefined) ?? 'New Notification',
|
||||
text2: msg.data?.body as string | undefined,
|
||||
position: 'top',
|
||||
visibilityTime: 4000,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user