Skip to content

Commit

Permalink
SCRUM-139 complete notification
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanli286 committed Oct 17, 2024
1 parent 18354cc commit 3194988
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion frontend/iQMA-Skills-Builder/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createContext, useEffect, useState} from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {router} from 'expo-router';
import messaging from '@react-native-firebase/messaging';
import { PermissionsAndroid } from 'react-native';
import { AppRegistry, PermissionsAndroid } from 'react-native';

export const AuthContext = createContext<any>(null);

Expand All @@ -13,6 +13,10 @@ export const AuthProvider = ({children}: {children: React.ReactNode}) => {
const [token, setToken] = useState<string | null>(null); // Store Access Token of current User
const [isLoading, setIsLoading] = useState(true);

messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});

const requestUserPermission = async () => {
try {
const permission = await PermissionsAndroid.request(
Expand Down Expand Up @@ -95,6 +99,9 @@ export const AuthProvider = ({children}: {children: React.ReactNode}) => {
const logIn = async () => {
try {
await authorize();
AppRegistry.registerHeadlessTask('ReactNativeFirebaseMessagingHeadlessTask', () => async (remoteMessage) => {
console.log('Message handled in the background (Headless Task):', remoteMessage);
});
} catch (e) {
console.log(e);
}
Expand Down

0 comments on commit 3194988

Please sign in to comment.