wip: needs testing on physical devices

This commit is contained in:
Loewy 2024-02-08 12:38:55 -08:00
parent baab800a1c
commit 6b8737e182
4 changed files with 30 additions and 24 deletions

View File

@ -30,19 +30,20 @@ export const confirmCode = async (
} }
}; };
export const createOrSignInUser = (
export const createOrSignInUser = (email: string, password: string, isSignUp: boolean) => { email: string,
console.log('isSignUp', isSignUp); password: string,
isSignUp: boolean,
) => {
console.log("isSignUp", isSignUp);
try { try {
if (isSignUp) { if (isSignUp) {
auth().createUserWithEmailAndPassword(email, password) auth().createUserWithEmailAndPassword(email, password);
} else { } else {
auth().signInWithEmailAndPassword(email, password) auth().signInWithEmailAndPassword(email, password);
} }
} catch (err) { } catch (err) {}
};
}
}
export const onAuthStateChanged = ( export const onAuthStateChanged = (
// TODO: eslint not detecting ts? // TODO: eslint not detecting ts?

View File

@ -13,6 +13,7 @@ import {
} from "react-native"; } from "react-native";
import { confirmCode, handleSignInWithPhoneNumber } from "../auth"; import { confirmCode, handleSignInWithPhoneNumber } from "../auth";
import { createOrSignInUser } from "../auth/firebase-auth"; import { createOrSignInUser } from "../auth/firebase-auth";
import { colors } from "../styles";
export default function Login() { export default function Login() {
const [isEmailLogin, setIsEmailLogin] = useState(false); const [isEmailLogin, setIsEmailLogin] = useState(false);
@ -23,9 +24,9 @@ export default function Login() {
const [code, setCode] = useState<string>(""); const [code, setCode] = useState<string>("");
const [confirm, setConfirm] = const [confirm, setConfirm] =
useState<FirebaseAuthTypes.ConfirmationResult | null>(null); useState<FirebaseAuthTypes.ConfirmationResult | null>(null);
// Email // Email
const [isSignUp, setIsSignUp] = useState<boolean>(false) const [isSignUp, setIsSignUp] = useState<boolean>(false);
const [email, setEmail] = useState<string>(""); const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>(""); const [password, setPassword] = useState<string>("");
const toggleSignUp = () => setIsSignUp(!isSignUp); const toggleSignUp = () => setIsSignUp(!isSignUp);
@ -34,10 +35,10 @@ export default function Login() {
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}> <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<View style={styles.container}> <View style={styles.container}>
<View style={styles.toggleRow}> <View style={styles.toggleRow}>
<Text>Use email</Text> <Text style={styles.toggleText}>Use email</Text>
<Switch <Switch
trackColor={{ false: "#767577", true: "#81b0ff" }} trackColor={{ false: colors.darkGrey, true: colors.lightGrey }}
thumbColor={isEmailLogin ? "#f5dd4b" : "#f4f3f4"} thumbColor={isEmailLogin ? colors.buttonBlue : colors.panelWhite}
onValueChange={toggleSwitch} onValueChange={toggleSwitch}
value={isEmailLogin} value={isEmailLogin}
/> />
@ -99,13 +100,15 @@ export default function Login() {
/> />
<TouchableOpacity onPress={toggleSignUp}> <TouchableOpacity onPress={toggleSignUp}>
<Text style={styles.linkText}> <Text style={styles.linkText}>
{isSignUp ? 'Already have an account? Sign In' : "Don't have an account? Sign Up"} {isSignUp
? "Already have an account? Sign In"
: "Don't have an account? Sign Up"}
</Text> </Text>
</TouchableOpacity> </TouchableOpacity>
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
<Button <Button
title={isSignUp ? 'SignUp' : 'Sign in'} title={isSignUp ? "SignUp" : "Sign in"}
onPress={() => createOrSignInUser(email, password, isSignUp)} onPress={() => createOrSignInUser(email, password, isSignUp)}
/> />
</View> </View>
@ -138,12 +141,13 @@ const styles = StyleSheet.create({
alignItems: "center", alignItems: "center",
marginBottom: 20, marginBottom: 20,
}, },
toggleText: { marginRight: 20, fontSize: 16 },
linkText: { linkText: {
fontSize: 16, fontSize: 16,
color: '#007AFF', color: "#007AFF",
paddingVertical: 10, paddingVertical: 10,
textAlign: 'center', textAlign: "center",
}, },
buttonContainer: { buttonContainer: {
width: "80%", width: "80%",
borderRadius: 25, borderRadius: 25,

View File

@ -7,14 +7,14 @@ import { useAuth } from "../context";
// Sign out button only functional when NOT using dev env // Sign out button only functional when NOT using dev env
export default function ProfileScreen() { export default function ProfileScreen() {
const { user } = useAuth(); const { user } = useAuth();
console.log(user) console.log(user);
return ( return (
<View style={styles.container}> <View style={styles.container}>
{user && ( {user && (
<> <>
<View style={styles.userInfo}> <View style={styles.userInfo}>
<Text>Display name: {user?.displayName ?? 'No username set'}</Text> <Text>Display name: {user?.displayName ?? "No username set"}</Text>
<Text>Phone number/Email: {user?.phoneNumber ?? user?.email}</Text> <Text>Phone number/Email: {user?.phoneNumber ?? user?.email}</Text>
</View> </View>
<View style={styles.signOutButton}> <View style={styles.signOutButton}>

View File

@ -4,6 +4,7 @@
export const colors = { export const colors = {
bgBlack: "#121212", bgBlack: "#121212",
lightGrey: "#BFC2C8", lightGrey: "#BFC2C8",
darkGrey: "#767577",
themeBrown: "#D9AA84", themeBrown: "#D9AA84",
panelWhite: "#F2FBFE", panelWhite: "#F2FBFE",
tournamentBlue: "#50a6c2", tournamentBlue: "#50a6c2",