You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1005 B
39 lines
1005 B
10 months ago
|
import { firebase } from "@react-native-firebase/messaging";
|
||
|
import { setFcmToken, setIsLogin, setUser } from "../appredux/actions"
|
||
|
import { store } from "../appredux/store";
|
||
|
|
||
|
|
||
|
export const clearAllState = () => {
|
||
|
store.dispatch(setIsLogin(false));
|
||
|
store.dispatch(setUser(null));
|
||
|
store.dispatch({type: 'LOGOUT'});
|
||
|
}
|
||
|
|
||
|
export const initFirebase = () => {
|
||
|
firebase.messaging().getToken().then((token) => {
|
||
|
_onChangeToken(token)
|
||
|
});
|
||
|
|
||
|
firebase.messaging().onTokenRefresh((token) => {
|
||
|
_onChangeToken(token)
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export const _onChangeToken = (token, language) => {
|
||
|
var data = {
|
||
|
'device_token': token,
|
||
|
'device_type': Platform.OS,
|
||
|
};
|
||
|
|
||
|
_loadDeviceInfo(data);
|
||
|
}
|
||
|
|
||
|
export const _loadDeviceInfo = async (deviceData) => {
|
||
|
try {
|
||
|
console.log('deviceData: ', deviceData)
|
||
|
store.dispatch(setFcmToken(deviceData.device_token));
|
||
|
}
|
||
|
catch (error) {
|
||
|
console.log('[App.js] _loadDeviceInfo error', error);
|
||
|
}
|
||
|
}
|