Skip to content

Commit

Permalink
Feat: receive FCM token
Browse files Browse the repository at this point in the history
  • Loading branch information
psh320 committed Jul 11, 2022
1 parent 50c086b commit 3f20062
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
23 changes: 22 additions & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import 'react-native-gesture-handler';
import {enableScreens} from 'react-native-screens';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {QueryClient, QueryClientProvider} from 'react-query';
import {getRegisterStatus, postToken} from './src/api';
import {getRegisterStatus, postFcmToken, postToken} from './src/api';
import messaging from '@react-native-firebase/messaging';

async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;

if (enabled) {
console.log('Authorization status:', authStatus);
}
}

enableScreens();

Expand All @@ -24,6 +36,15 @@ export default function App() {
// 실행하면 가장 먼저 로컬에 로그인 정보 있는지 확인
useEffect(() => {
getToken();

requestUserPermission();

messaging()
.getToken()
.then((token) => {
return postFcmToken(token);
});

const id = setTimeout(() => {
setLoading(false);
}, 2000);
Expand Down
11 changes: 10 additions & 1 deletion src/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const getRegisterStatus = async () => {
const response = await customAxios().get('/api/v1/users/me/register-status');
return response.data.result.registerStatus;
} catch (error) {
console.log('register Status', error);
console.log('회원가입 상태 정보 받기 실패', error);
}
};

export const postFcmToken = async (token: string) => {
try {
const response = await customAxios().post('/api/v1/fcm/me', token);
return response.data;
} catch (error) {
console.log('파이어베이스 토큰 받기 실패', error);
}
};

0 comments on commit 3f20062

Please sign in to comment.