This repository has been archived on 2026-04-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
interaktive-systeme/app/login.tsx
2023-12-08 17:31:28 +01:00

55 lines
No EOL
1.8 KiB
TypeScript

import { View, Text, SafeAreaView, TextInput, Button} from 'react-native'
import React, { useEffect, useState } from 'react'
import { useAuth } from './contexts/AuthContext'
import { Redirect } from 'expo-router';
import { FontAwesome } from "@expo/vector-icons";
import { Input } from '../components';
import { useThemeColor } from '../hooks/hooks';
export default function login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("")
const {authState, onLogin} = useAuth()
const backgroundColor = useThemeColor("backgroundColor")
const textColor = useThemeColor("primaryText");
const elementDefaultColor = useThemeColor("elementDefaultColor")
// const {authState, onLogin} = useAuth();
// useEffect(() => {
// login()
// }, [])
const login = async() => {
await onLogin!(email, password);
}
return (
<SafeAreaView style={{flex: 1, justifyContent: "center", backgroundColor: backgroundColor}}>
{authState?.authenticated &&
<Redirect href={"/"}></Redirect>}
<Input
placeholder={'Enter Email'}
label='Email or Username'
labelColor={textColor}
leftIcon={<FontAwesome name="user" size={20} color={textColor} />}
onChangeHandler={setEmail}
bgColor ={elementDefaultColor}
/>
<Input
placeholder={'Enter Password'}
label='Password'
labelColor={textColor}
leftIcon={<FontAwesome name="key" size={20} color={textColor}/>}
onChangeHandler={setPassword}
bgColor ={elementDefaultColor}
secure = {true}
/>
<Button title='Login' onPress={login}></Button>
</SafeAreaView>
);
}