Feature/notification system #26
5 changed files with 35 additions and 55 deletions
11
app.json
11
app.json
|
|
@ -34,16 +34,7 @@
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"expo-router",
|
"expo-router",
|
||||||
"expo-font",
|
"expo-font",
|
||||||
"expo-web-browser",
|
"expo-web-browser"
|
||||||
"@react-native-firebase/app",
|
|
||||||
[
|
|
||||||
"expo-build-properties",
|
|
||||||
{
|
|
||||||
"ios": {
|
|
||||||
"useFrameworks": "static"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
"experiments": {
|
"experiments": {
|
||||||
"typedRoutes": true
|
"typedRoutes": true
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import messaging from '@react-native-firebase/messaging';
|
import * as Notifications from 'expo-notifications';
|
||||||
import { router } from 'expo-router';
|
import { router } from 'expo-router';
|
||||||
import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth';
|
import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth';
|
||||||
import { auth } from '@/contexts/firebase';
|
import { auth } from '@/contexts/firebase';
|
||||||
|
|
@ -52,7 +52,35 @@ export default function Register() {
|
||||||
await updateProfile(userCredential.user, {
|
await updateProfile(userCredential.user, {
|
||||||
displayName: `${values.firstName} ${values.lastName}`
|
displayName: `${values.firstName} ${values.lastName}`
|
||||||
});
|
});
|
||||||
const token = await messaging().getToken();
|
// Request permissions and get push token (native FCM if possible, else Expo token)
|
||||||
|
let token = null;
|
||||||
|
let tokenType = null;
|
||||||
|
const { status: existingStatus } = await Notifications.getPermissionsAsync();
|
||||||
|
let finalStatus = existingStatus;
|
||||||
|
if (existingStatus !== 'granted') {
|
||||||
|
const { status } = await Notifications.requestPermissionsAsync();
|
||||||
|
finalStatus = status;
|
||||||
|
}
|
||||||
|
if (finalStatus === 'granted') {
|
||||||
|
try {
|
||||||
|
// Try to get native FCM token (works in dev/prod builds, not Expo Go)
|
||||||
|
const deviceToken = await Notifications.getDevicePushTokenAsync({ provider: 'fcm' });
|
||||||
|
if (deviceToken?.data) {
|
||||||
|
token = deviceToken.data;
|
||||||
|
tokenType = 'fcm';
|
||||||
|
} else {
|
||||||
|
// Fallback to Expo push token
|
||||||
|
const expoToken = await Notifications.getExpoPushTokenAsync();
|
||||||
|
token = expoToken.data;
|
||||||
|
tokenType = 'expo';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback to Expo push token if native fails
|
||||||
|
const expoToken = await Notifications.getExpoPushTokenAsync();
|
||||||
|
token = expoToken.data;
|
||||||
|
tokenType = 'expo';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await postgresServices.createUser({
|
await postgresServices.createUser({
|
||||||
firstName: values.firstName,
|
firstName: values.firstName,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import { initializeApp } from 'firebase/app';
|
import { initializeApp } from 'firebase/app';
|
||||||
import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
|
import { getAuth } from 'firebase/auth';
|
||||||
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
|
|
||||||
|
|
||||||
const firebaseConfig = {
|
const firebaseConfig = {
|
||||||
apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
|
apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
|
||||||
|
|
@ -12,9 +12,8 @@ const firebaseConfig = {
|
||||||
appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
|
appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const app = initializeApp(firebaseConfig);
|
const app = initializeApp(firebaseConfig);
|
||||||
const auth = initializeAuth(app, {
|
const auth = getAuth(app);
|
||||||
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
|
|
||||||
});
|
|
||||||
|
|
||||||
export { auth };
|
export { auth };
|
||||||
|
|
|
||||||
36
package-lock.json
generated
36
package-lock.json
generated
|
|
@ -12,8 +12,6 @@
|
||||||
"@emotion/unitless": "^0.10.0",
|
"@emotion/unitless": "^0.10.0",
|
||||||
"@expo/vector-icons": "^14.0.2",
|
"@expo/vector-icons": "^14.0.2",
|
||||||
"@react-native-async-storage/async-storage": "^1.24.0",
|
"@react-native-async-storage/async-storage": "^1.24.0",
|
||||||
"@react-native-firebase/app": "^23.1.1",
|
|
||||||
"@react-native-firebase/messaging": "^23.1.1",
|
|
||||||
"@react-native-picker/picker": "^2.11.1",
|
"@react-native-picker/picker": "^2.11.1",
|
||||||
"@react-navigation/native": "^7.1.17",
|
"@react-navigation/native": "^7.1.17",
|
||||||
"expo": "^53.0.20",
|
"expo": "^53.0.20",
|
||||||
|
|
@ -3118,40 +3116,6 @@
|
||||||
"react-native": "^0.0.0-0 || >=0.60 <1.0"
|
"react-native": "^0.0.0-0 || >=0.60 <1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@react-native-firebase/app": {
|
|
||||||
"version": "23.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@react-native-firebase/app/-/app-23.1.1.tgz",
|
|
||||||
"integrity": "sha512-w6fSGukDPzHiDbF3d8g1MYrlcoHtAn0pezUDYcmhZjDMldPBb5yxDi8/tj96K+0AecY6nCbOh5VgwY0bEd3iOQ==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"firebase": "12.1.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"expo": ">=47.0.0",
|
|
||||||
"react": "*",
|
|
||||||
"react-native": "*"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"expo": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@react-native-firebase/messaging": {
|
|
||||||
"version": "23.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@react-native-firebase/messaging/-/messaging-23.1.1.tgz",
|
|
||||||
"integrity": "sha512-P6jH3jGGXIDn+EuCognMWkegqR/cDmEAMXHLV+XgodCSMoMODBfswJWmKYoX/7xkjBsptOXUKI6uwo3S+H5z1Q==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"peerDependencies": {
|
|
||||||
"@react-native-firebase/app": "23.1.1",
|
|
||||||
"expo": ">=47.0.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"expo": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@react-native-picker/picker": {
|
"node_modules/@react-native-picker/picker": {
|
||||||
"version": "2.11.1",
|
"version": "2.11.1",
|
||||||
"resolved": "https://registry.npmjs.org/@react-native-picker/picker/-/picker-2.11.1.tgz",
|
"resolved": "https://registry.npmjs.org/@react-native-picker/picker/-/picker-2.11.1.tgz",
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@
|
||||||
"@emotion/unitless": "^0.10.0",
|
"@emotion/unitless": "^0.10.0",
|
||||||
"@expo/vector-icons": "^14.0.2",
|
"@expo/vector-icons": "^14.0.2",
|
||||||
"@react-native-async-storage/async-storage": "^1.24.0",
|
"@react-native-async-storage/async-storage": "^1.24.0",
|
||||||
"@react-native-firebase/app": "^23.1.1",
|
|
||||||
"@react-native-firebase/messaging": "^23.1.1",
|
|
||||||
"@react-native-picker/picker": "^2.11.1",
|
"@react-native-picker/picker": "^2.11.1",
|
||||||
"@react-navigation/native": "^7.1.17",
|
"@react-navigation/native": "^7.1.17",
|
||||||
"expo": "^53.0.20",
|
"expo": "^53.0.20",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue