wip: working, needs some unit tests for auth functions

This commit is contained in:
Loewy
2024-02-06 11:09:22 -08:00
parent d93d73dc3a
commit eb2534ff94
5 changed files with 31 additions and 22 deletions

View File

@@ -8,10 +8,11 @@ import {
TouchableWithoutFeedback,
View,
} from 'react-native';
import { signInWithPhoneNumber, confirmCode, onAuthStateChanged, signOut } from '../auth'; // Adjust the path as necessary
import { handleSignInWithPhoneNumber, confirmCode, onAuthStateChanged } from '../auth';
import { FirebaseAuthTypes } from '@react-native-firebase/auth';
import { useAuthHeader } from '../graphql/client';
import AsyncStorage from '@react-native-async-storage/async-storage';
import SignOutButton from '../component/buttons/sign-out';
export default function Login() {
const [phoneNumber, setPhoneNumber] = useState<string>('');
@@ -22,9 +23,6 @@ export default function Login() {
useEffect(() => {
const unsubscribe = onAuthStateChanged(async (user) => {
console.log('🦊 | useFirebaseAuthSetup | onAuthStateChanged | user:', user);
// TODO: see if should save the user in the store or use those info some how or not, ot just need the accessToken
setUser(user)
if (user) {
const token = await user.getIdToken()
@@ -33,7 +31,6 @@ export default function Login() {
setAuthHeader({ key: "Authorization", value: `Bearer ${token}` });
}
}
console.log('🦛 | user.emailVerified:', user?.emailVerified);
});
return unsubscribe;
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -78,7 +75,7 @@ export default function Login() {
)}
<Button
title={!confirm ? 'Receive code' : 'Confirm code'}
onPress={() => !confirm ? signInWithPhoneNumber(phoneNumber).then(setConfirm) : confirm && confirmCode(confirm, code)}
onPress={() => !confirm ? handleSignInWithPhoneNumber(phoneNumber).then(setConfirm) : confirm && confirmCode(confirm, code)}
/>
<Text>{authHeader.key}: {authHeader.value}</Text>
{user && (
@@ -88,13 +85,7 @@ export default function Login() {
</Text>
<Text>Phone number: {user?.phoneNumber}</Text>
<Button
title={'Sign out'}
onPress={() => {
setAuthHeader({ key: 'Authorization', value: '' })
signOut()
}}
/>
<SignOutButton />
</>
)}
</View>