-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNativeFacebookButton.tsx
More file actions
41 lines (32 loc) · 1.29 KB
/
NativeFacebookButton.tsx
File metadata and controls
41 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useAuthFacebookControllerLogin } from '@baca/api/query/auth-social/auth-social'
import { isExpoGo, isWeb } from '@baca/constants'
import { assignPushToken, setToken } from '@baca/services'
import { isSignedInAtom, store } from '@baca/store'
import { SocialButton } from '../SocialButton'
export const NativeFacebookButton = () => {
const { mutate: loginWithFacebook } = useAuthFacebookControllerLogin()
if (isExpoGo || isWeb) return null
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { AccessToken, LoginManager } = require('react-native-fbsdk-next')
const handleLogin = async () => {
await LoginManager.logInWithPermissions(['email', 'public_profile'], 'enabled')
const { accessToken } = (await AccessToken.getCurrentAccessToken()) || {}
accessToken &&
loginWithFacebook(
{ data: { accessToken } },
{
onSuccess: async (response) => {
const { user, ...token } = response
if (token) {
await setToken(token)
}
store.set(isSignedInAtom, true)
// Send push token to backend
await assignPushToken()
},
}
)
}
// eslint-disable-next-line react/jsx-no-bind
return <SocialButton type="facebook" onPress={handleLogin} />
}