Skip to content

Commit

Permalink
Okay, this time for real
Browse files Browse the repository at this point in the history
  • Loading branch information
StarNumber12046 committed Sep 17, 2024
1 parent 7f3b641 commit 72ff44c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions app/onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef, useContext } from "react";
import messaging, {
firebase,
FirebaseMessagingTypes,
} from "@react-native-firebase/messaging";
import { ProfileContext } from "./_layout";
import { Text, View, Pressable, StyleSheet } from "react-native";
import * as Notifications from "expo-notifications";
import { router } from "expo-router";
import firebaseConfig from "@/creds";
import { getMyProfile } from "@/sdk";

if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
Expand All @@ -15,15 +16,6 @@ if (!firebase.apps.length) {
}
// Initialize Firebase only if it's not initialized

Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
priority: Notifications.AndroidNotificationPriority.HIGH,
}),
});

function handleRegistrationError(errorMessage: string) {
alert(errorMessage);
throw new Error(errorMessage);
Expand Down Expand Up @@ -94,7 +86,11 @@ export default function Onboarding() {

async function onClick() {
const pushTokenString = await registerForPushNotificationsAsync();
const body = { fcmToken: pushTokenString, region: "europe-west" };
const userContext = useContext(ProfileContext);
const body = {
fcmToken: pushTokenString,
region: (await getMyProfile(userContext)).region,
};

const res = await fetch("https://rebeal-server.vercel.app/register", {
body: JSON.stringify(body),
Expand Down

0 comments on commit 72ff44c

Please sign in to comment.