working with email on create user / sign in -- not getting expected error from firebase
This commit is contained in:
parent
e2bde3bd01
commit
baab800a1c
@ -30,6 +30,20 @@ export const confirmCode = async (
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const createOrSignInUser = (email: string, password: string, isSignUp: boolean) => {
|
||||
console.log('isSignUp', isSignUp);
|
||||
try {
|
||||
if (isSignUp) {
|
||||
auth().createUserWithEmailAndPassword(email, password)
|
||||
} else {
|
||||
auth().signInWithEmailAndPassword(email, password)
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const onAuthStateChanged = (
|
||||
// TODO: eslint not detecting ts?
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
@ -7,25 +7,28 @@ import {
|
||||
Switch,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
TouchableWithoutFeedback,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { confirmCode, handleSignInWithPhoneNumber } from "../auth";
|
||||
import { createOrSignInUser } from "../auth/firebase-auth";
|
||||
|
||||
export default function Login() {
|
||||
const [isEmailLogin, setIsEmailLogin] = useState(false);
|
||||
const toggleSwitch = () => setIsEmailLogin((previousState) => !previousState);
|
||||
|
||||
// Phone number
|
||||
const [phoneNumber, setPhoneNumber] = useState<string>("");
|
||||
const [code, setCode] = useState<string>("");
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const [confirm, setConfirm] =
|
||||
useState<FirebaseAuthTypes.ConfirmationResult | null>(null);
|
||||
|
||||
const toggleSwitch = () => setIsEmailLogin((previousState) => !previousState);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
||||
const handleSignInWithEmail = (email: string, password: string) =>
|
||||
console.log("signingInWithEmail");
|
||||
// Email
|
||||
const [isSignUp, setIsSignUp] = useState<boolean>(false)
|
||||
const [email, setEmail] = useState<string>("");
|
||||
const [password, setPassword] = useState<string>("");
|
||||
const toggleSignUp = () => setIsSignUp(!isSignUp);
|
||||
|
||||
return (
|
||||
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
|
||||
@ -94,11 +97,16 @@ export default function Login() {
|
||||
value={password}
|
||||
onChangeText={setPassword}
|
||||
/>
|
||||
<TouchableOpacity onPress={toggleSignUp}>
|
||||
<Text style={styles.linkText}>
|
||||
{isSignUp ? 'Already have an account? Sign In' : "Don't have an account? Sign Up"}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<View style={styles.buttonContainer}>
|
||||
<Button
|
||||
title="Sign in"
|
||||
onPress={() => handleSignInWithEmail(email, password)}
|
||||
title={isSignUp ? 'SignUp' : 'Sign in'}
|
||||
onPress={() => createOrSignInUser(email, password, isSignUp)}
|
||||
/>
|
||||
</View>
|
||||
</>
|
||||
@ -129,6 +137,12 @@ const styles = StyleSheet.create({
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
},
|
||||
linkText: {
|
||||
fontSize: 16,
|
||||
color: '#007AFF',
|
||||
paddingVertical: 10,
|
||||
textAlign: 'center',
|
||||
},
|
||||
buttonContainer: {
|
||||
width: "80%",
|
||||
|
@ -7,14 +7,15 @@ import { useAuth } from "../context";
|
||||
// Sign out button only functional when NOT using dev env
|
||||
export default function ProfileScreen() {
|
||||
const { user } = useAuth();
|
||||
console.log(user)
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
{user && (
|
||||
<>
|
||||
<View style={styles.userInfo}>
|
||||
<Text>Display name: {user?.displayName}</Text>
|
||||
<Text>Phone number: {user?.phoneNumber}</Text>
|
||||
<Text>Display name: {user?.displayName ?? 'No username set'}</Text>
|
||||
<Text>Phone number/Email: {user?.phoneNumber ?? user?.email}</Text>
|
||||
</View>
|
||||
<View style={styles.signOutButton}>
|
||||
<SignOutButton />
|
||||
|
Loading…
Reference in New Issue
Block a user