1
0
forked from fr/deguapp
deguapp/frontend/app/login.js

118 lines
2.7 KiB
JavaScript
Raw Normal View History

import { StyleSheet, TextInput, View, Text, Image } from "react-native";
import { useEffect, useState } from "react";
import { router } from "expo-router";
2024-05-05 17:44:42 +02:00
import Button from "../components/Button";
import { colors } from "../components/style";
import { useAuth } from "./context/AuthContext";
function LoginPage() {
const [pass, setPass] = useState("");
const [email, setEmail] = useState("");
const { onLogin, authState } = useAuth();
useEffect(() => {
if (authState.authenticated) {
router.replace("/");
}
}, [authState.authenticated]);
function login() {
onLogin(email, pass);
}
2024-05-05 17:44:42 +02:00
return (
<View style={styles.container}>
2024-05-05 18:46:02 +02:00
<View style={styles.header}>
<Image
source={require("../assets/deguapp_logo.png")}
style={styles.logo}
/>
<Text style={styles.h1}>Please Log In</Text>
</View>
<View style={styles.form}>
<TextInput
style={styles.input}
placeholder="Enter your email"
autoCapitalize="none"
autoCompleteType="email"
textContentType="emailAddress"
keyboardType="email-address"
placeholderTextColor={"#aaaaaa"}
returnKeyType="next"
value={email}
onChangeText={(text) => setEmail(text)}
2024-05-05 18:46:02 +02:00
/>
<TextInput
style={styles.input}
secureTextEntry={true}
placeholder="Enter your password"
placeholderTextColor={"#aaaaaa"}
returnKeyType="done"
value={pass}
onChangeText={(text) => setPass(text)}
2024-05-05 18:46:02 +02:00
/>
<View style={styles.btnContainer}>
<Button
style={styles.button}
title="Sign Up"
color={colors.charcoal}
onPress={() => router.replace("/signup")}
2024-05-05 18:46:02 +02:00
/>
<Button
style={styles.button}
title="Log In"
color={colors.gold}
onPress={login}
2024-05-05 18:46:02 +02:00
/>
</View>
2024-05-05 17:44:42 +02:00
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
2024-05-05 18:46:02 +02:00
width: "100%",
height: "100%",
2024-05-05 17:44:42 +02:00
backgroundColor: colors.dark,
2024-05-05 18:46:02 +02:00
},
form: {
2024-05-05 17:44:42 +02:00
flex: 1,
alignItems: "center",
2024-05-05 18:46:02 +02:00
paddingTop: "10%",
2024-05-05 17:44:42 +02:00
width: "100%",
2024-05-05 18:46:02 +02:00
gap: 15,
2024-05-05 17:44:42 +02:00
},
2024-05-05 18:46:02 +02:00
h1: {
2024-05-05 17:44:42 +02:00
color: "#FFF",
2024-05-05 18:46:02 +02:00
fontSize: 30,
textAlign: "center",
paddingTop: "20%",
},
logo: {
width: "80%",
resizeMode: "contain",
},
header: {
width: "100%",
alignItems: "center",
paddingTop: "20%",
2024-05-05 17:44:42 +02:00
},
input: {
height: "auto",
width: "60%",
borderColor: "gray",
borderWidth: 1,
borderRadius: 5,
padding: 10,
color: "#fff",
2024-05-05 17:44:42 +02:00
},
btnContainer: {
flexDirection: "row",
2024-05-05 18:46:02 +02:00
gap: 5,
2024-05-05 17:44:42 +02:00
},
});
export default LoginPage;