<aside> 💡 i take @react-native-google-signin/google-signin package that return idToken, serverAuthCodes
but in firebase console > authentication > User doesn't exist Logged User
I want to see Logged User what more should i do ?
</aside>
import React, {useCallback, useEffect, useState} from 'react'
import type {FC} from 'react';
import {StyleSheet, View, Text, SafeAreaView, ScrollView, Button, StatusBar, TouchableOpacity, Image} from 'react-native'
import styled from 'styled-components/native';
import {
GoogleSignin,
GoogleSigninButton,
statusCodes,
} from '@react-native-google-signin/google-signin';
import * as D from '../data'
export type IdentificationProps = {
onNavigate: any
};
const StoryCard: FC<IdentificationProps> = ({
onNavigate
}) => {
useEffect(() => {
GoogleSignin.configure({
scopes: ['<https://www.googleapis.com/auth/drive.readonly>'],
webClientId:
'###', // client ID of type WEB for your server (needed to verify user ID and offline access)
offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER
});
}, []);
const goRouter = useCallback(() => {
/**
onNavigate(!modalVisible)
*/
},[]);
const [loggedIn, setLoggedIn] = useState(false);
const [userInfoData, setUserInfoData] = useState<D.IUser>({
user: {
id: '',
name: null,
email: '',
photo: null,
familyName: null,
givenName: null,
},
idToken: null,
serverAuthCode: null,
});
const signIn = async () => {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
setUserInfoData(userInfo);
setLoggedIn(true);
console.log('userInfo :', userInfo);
console.log('토큰 :', userInfo.idToken);
onNavigate(userInfo.idToken);
} catch (error) {
console.error('error:', error);
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
// user cancelled the login flow
} else if (error.code === statusCodes.IN_PROGRESS) {
// operation (e.g. sign in) is in progress alreadydfdd
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
// play services not available or outdated
} else {
// some other error happened
}
}
};
const signOut = async () => {
try {
await GoogleSignin.revokeAccess();
await GoogleSignin.signOut();
setLoggedIn(false);
setUserInfoData({
user: {
id: '',
name: null,
email: '',
photo: null,
familyName: null,
givenName: null,
},
idToken: null,
serverAuthCode: null
});
} catch (error) {
console.error(error);
}
}
return (
<>
<TouchableOpacity activeOpacity={0.8} style={[styles.signButton, {marginBottom: 20}]} onPress={signIn}>
<Image
style={{width: 30, height: 30, position: 'absolute', left: 14}}
source={require('../assets/images/google.png')}
/>
<Text style={[styles.btnText]}>Google로 로그인</Text>
</TouchableOpacity>
</>
)
}