This commit is contained in:
Jamie Brunton committed 2025-12-28 21:56:20 +00:00
1 parent 6ff5bc62f2
commit adab288a3a
204 files changed
+11334 -14295

No files matched your search

+43
View File
@@ -1,6 +1,20 @@
// Web polyfills must be imported FIRST before any other React Native imports
import "../src/polyfills/web";
// Initialize Sentry early to capture all errors
import { initSentry, setUserContext, clearUserContext } from "../src/lib/sentry";
initSentry();
// Import push notification utilities
import {
registerForPushNotificationsAsync,
savePushToken,
clearPushToken,
setupNotificationResponseListener,
getInitialNotification,
handleNotificationResponse,
} from "../src/lib/notifications";
import React, { useEffect } from "react";
import { Platform, View } from "react-native";
@@ -56,13 +70,41 @@ export default function RootLayout() {
handleDeepLink(event.url);
});
// Set up push notification response listener (for taps while app is running)
const notificationSubscription = setupNotificationResponseListener();
// Check if app was opened from a notification tap (cold start)
getInitialNotification().then((response) => {
if (response) {
handleNotificationResponse(response);
}
});
// Listen for auth changes
const { data: { subscription: authSubscription } } = supabase.auth.onAuthStateChange(
async (event, session) => {
if (event === "SIGNED_IN" || event === "TOKEN_REFRESHED") {
fetchUser();
// Set Sentry user context for error tracking
if (session?.user) {
setUserContext(session.user.id, session.user.email);
// Register for push notifications and save token
const token = await registerForPushNotificationsAsync();
if (token) {
await savePushToken(session.user.id, token);
}
}
} else if (event === "SIGNED_OUT") {
// Clear push token before clearing user state
const userId = useAuthStore.getState().user?.id;
if (userId) {
await clearPushToken(userId);
}
setUser(null);
clearUserContext();
// Clear React Query cache
queryClient.clear();
}
}
);
@@ -70,6 +112,7 @@ export default function RootLayout() {
return () => {
linkingSubscription.remove();
authSubscription.unsubscribe();
notificationSubscription.remove();
};
}, []);