Calendar, syncing rework

This commit is contained in:
Milan Paunovic
2024-11-27 01:37:58 +01:00
parent f2af60111b
commit 95d5e74703
9 changed files with 629 additions and 174 deletions

View File

@ -21,6 +21,20 @@ import { DeviceType } from "expo-device";
if (Platform.OS === "ios") KeyboardManager.setEnableAutoToolbar(true);
const firebaseAuthErrors: { [key: string]: string } = {
'auth/invalid-email': 'Please enter a valid email address',
'auth/user-disabled': 'This account has been disabled. Please contact support',
'auth/user-not-found': 'No account found with this email address',
'auth/wrong-password': 'Incorrect password. Please try again',
'auth/email-already-in-use': 'An account with this email already exists',
'auth/operation-not-allowed': 'This login method is not enabled. Please contact support',
'auth/weak-password': 'Password should be at least 6 characters',
'auth/invalid-credential': 'Invalid login credentials. Please try again',
'auth/network-request-failed': 'Network error. Please check your internet connection',
'auth/too-many-requests': 'Too many failed login attempts. Please try again later',
'auth/invalid-login-credentials': 'Invalid email or password. Please try again',
};
const SignInPage = () => {
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
@ -51,21 +65,25 @@ const SignInPage = () => {
const router = useRouter();
const handleSignIn = async () => {
await signIn({ email, password });
if (!isError) {
Toast.show({
type: "success",
text1: "Login successful!",
});
} else {
Toast.show({
type: "error",
text1: "Error logging in",
text2: `${error}`,
});
}
};
const handleSignIn = async () => {
try {
await signIn({ email, password });
Toast.show({
type: "success",
text1: "Login successful!",
});
} catch (error: any) {
const errorCode = error?.code || 'unknown-error';
const errorMessage = firebaseAuthErrors[errorCode] || 'An unexpected error occurred. Please try again';
Toast.show({
type: "error",
text1: "Error logging in",
text2: errorMessage,
});
}
};
return (
<SafeAreaView style={{ flex: 1, alignItems: isTablet ? "center" : undefined}}>
@ -138,11 +156,11 @@ const SignInPage = () => {
backgroundColor="#fd1775"
/>
{isError && (
<Text center style={{ marginBottom: 20 }}>{`${
error?.toString()?.split("]")?.[1]
}`}</Text>
)}
{isError && (
<Text center style={{ marginBottom: 20 }}>
{firebaseAuthErrors[error?.code] || 'An unexpected error occurred. Please try again'}
</Text>
)}
<View row centerH marginB-5 gap-5>
<Text style={styles.jakartaLight}>Don't have an account?</Text>