Skip to content

Commit

Permalink
Fixed invalid password issue (#55)
Browse files Browse the repository at this point in the history
* Fixed invalid password issue

* Removed unfinished email check

* Fixed margin spacing
  • Loading branch information
kaceyna authored Nov 21, 2024
1 parent e453c84 commit 1a75b95
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions components/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import {
Alert,
StyleSheet,
Expand All @@ -10,13 +10,25 @@ import {
import { supabase } from "../utils/supabase";
import { SymbolView } from "expo-symbols";
import { Theme, useTheme } from "../utils/ThemeProvider";
import { router } from "expo-router";
import { router, useNavigation } from "expo-router";

export default function Auth() {
const styles = getStyles(useTheme());
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const [showPasswordError, setShowPasswordError] = useState(false);
const navigation = useNavigation();

// Reset states on load
useEffect(() => {
const unsubscribe = navigation.addListener("focus", () => {
setShowPasswordError(false);
setEmail("");
setPassword("");
});
return unsubscribe;
}, [navigation]);

async function signInWithEmail() {
setLoading(true);
Expand All @@ -37,6 +49,8 @@ export default function Auth() {

if (error) {
Alert.alert(error.message);
} else if (password.length < 6) {
setShowPasswordError(true);
} else {
router.replace({
pathname: "/account/choose-username",
Expand Down Expand Up @@ -84,6 +98,12 @@ export default function Auth() {
value={password}
/>
</View>
{showPasswordError && (
<Text style={styles.errorMessage}>
Invalid password{"\n"}
(Must be 6 or more characters)
</Text>
)}
<View style={styles.buttons}>
<TouchableOpacity disabled={loading} onPress={() => signInWithEmail()}>
<Text>Login</Text>
Expand Down Expand Up @@ -125,4 +145,10 @@ const getStyles = (theme: Theme) =>
padding: 10,
minWidth: "80%",
},
errorMessage: {
textAlign: "center",
color: theme.error,
fontSize: 14,
marginBottom: "5%",
},
});

0 comments on commit 1a75b95

Please sign in to comment.