-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4c5ba7
commit 1cbfa7e
Showing
5 changed files
with
250 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { SafeAreaView, Button, Text } from "react-native"; | ||
import { styles } from "../style"; | ||
import { auth, signOut, onAuthStateChanged } from "../auth"; | ||
import { useState } from "react"; | ||
export default function App({ navigation }) { | ||
const [name, setName] = useState(""); | ||
onAuthStateChanged(auth, (user) => { | ||
if (user) { | ||
const name = user.email.split("@")[0]; | ||
setName(name); | ||
} | ||
}); | ||
const LogoutUser = () => { | ||
signOut(auth) | ||
.then(() => { | ||
console.log("signed out"); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<Text>Hello {name}</Text> | ||
<Button title="Logout" onPress={LogoutUser} /> | ||
</SafeAreaView> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { | ||
View, | ||
SafeAreaView, | ||
Image, | ||
TextInput, | ||
Text, | ||
TouchableOpacity, | ||
} from "react-native"; | ||
import { StatusBar } from "expo-status-bar"; | ||
import { styles } from "../style"; | ||
import { useState, useEffect } from "react"; | ||
import { auth, signInWithEmailAndPassword } from "../auth"; | ||
|
||
export default function App({ navigation }) { | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
// | ||
useEffect(() => { | ||
const unsubscribe = auth.onAuthStateChanged((user) => { | ||
if (user) { | ||
navigation.navigate("Dashboard"); | ||
} else { | ||
navigation.navigate("Login"); | ||
} | ||
setUsername(""); | ||
setPassword(""); | ||
this.usrnmInp.clear(); | ||
this.pswdInp.clear(); | ||
}); | ||
return unsubscribe; | ||
}, []); | ||
// | ||
const LoginUser = () => { | ||
// | ||
signInWithEmailAndPassword(auth, username, password) | ||
.then((userCredential) => { | ||
// Signed in | ||
const user = userCredential.user; | ||
console.log("logged in as: " + user.email); | ||
// ... | ||
}) | ||
.catch((error) => { | ||
const errorCode = error.code; | ||
const errorMessage = error.message; | ||
console.log(errorCode); | ||
console.log(errorMessage); | ||
}); | ||
}; | ||
// | ||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<StatusBar style="auto" /> | ||
<View style={styles.bg}></View> | ||
<View style={styles.loginScreen}> | ||
<View style={styles.loginScreen.cehsLogo}> | ||
<Image | ||
source={require("../assets/cehs.png")} | ||
style={{ height: "100%", resizeMode: "contain" }} | ||
/> | ||
</View> | ||
<Text | ||
style={{ | ||
backgroundColor: "#8300fd", | ||
color: "#fff", | ||
width: "100%", | ||
textAlign: "center", | ||
fontSize: 20, | ||
paddingVertical: 10, | ||
}} | ||
> | ||
Welcome To Notifire | ||
</Text> | ||
<View style={styles.loginScreen.loginInputs}> | ||
<TextInput | ||
autoComplete="email" | ||
placeholder="Username" | ||
autoCapitalize="none" | ||
onChangeText={(usrnm) => setUsername(usrnm)} | ||
placeholderTextColor={"#949494"} | ||
keyboardType="email-address" | ||
style={styles.loginScreen.loginInputs.username} | ||
ref={(inp) => { | ||
this.usrnmInp = inp; | ||
}} | ||
/> | ||
<TextInput | ||
placeholder="Password" | ||
autoCapitalize="none" | ||
placeholderTextColor={"#949494"} | ||
onChangeText={(pswd) => setPassword(pswd)} | ||
secureTextEntry={true} | ||
style={styles.loginScreen.loginInputs.password} | ||
ref={(inp) => { | ||
this.pswdInp = inp; | ||
}} | ||
/> | ||
|
||
<TouchableOpacity | ||
onPress={() => { | ||
if (username.trim() && password.trim()) { | ||
LoginUser; | ||
} | ||
}} | ||
style={styles.loginScreen.loginInputs.loginBtn} | ||
> | ||
<Text>Login</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { StyleSheet, Platform } from "react-native"; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
overflow: "hidden", | ||
flex: 1, | ||
backgroundColor: "#fff", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}, | ||
bg: { | ||
flex: 0.5, | ||
backgroundColor: "dodgerblue", | ||
height: "100%", | ||
width: "200%", | ||
position: "absolute", | ||
top: "-50%", | ||
left: "-50%", | ||
transform: "rotate(-15deg)", | ||
}, | ||
loginScreen: { | ||
height: "85%", | ||
width: "80%", | ||
backgroundColor: "#fff", | ||
borderRadius: 10, | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
cehsLogo: { | ||
width: "100%", | ||
flex: 1.8, | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}, | ||
loginInputs: { | ||
flex: 1.2, | ||
width: "100%", | ||
minHeight: 100, | ||
height: 100, | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
gap: 20, | ||
username: { | ||
width: "80%", | ||
backgroundColor: "#ebebeb", | ||
paddingVertical: 8, | ||
paddingHorizontal: 16, | ||
borderRadius: 6, | ||
}, | ||
password: { | ||
width: "80%", | ||
backgroundColor: "#ebebeb", | ||
paddingVertical: 8, | ||
paddingHorizontal: 16, | ||
borderRadius: 6, | ||
}, | ||
loginBtn: { | ||
paddingVertical: 10, | ||
paddingHorizontal: 25, | ||
marginTop: 10, | ||
borderRadius: 100, | ||
...Platform.select({ | ||
default: { | ||
shadowColor: "#000", | ||
shadowOffset: { width: 0, height: 3 }, | ||
shadowRadius: 5, | ||
shadowOpacity: 0.4, | ||
}, | ||
ios: { | ||
shadowColor: "#000", | ||
shadowOffset: { width: 0, height: 3 }, | ||
shadowRadius: 5, | ||
shadowOpacity: 0.4, | ||
}, | ||
android: { | ||
elevation: 2, | ||
}, | ||
}), | ||
}, | ||
}, | ||
...Platform.select({ | ||
default: { | ||
shadowColor: "#000", | ||
shadowOffset: { width: 0, height: 10 }, | ||
shadowRadius: 15, | ||
shadowOpacity: 0.5, | ||
}, | ||
ios: { | ||
shadowColor: "#000", | ||
shadowOffset: { width: 0, height: 10 }, | ||
shadowRadius: 15, | ||
shadowOpacity: 0.5, | ||
}, | ||
android: { | ||
elevation: 8, | ||
}, | ||
}), | ||
}, | ||
}); | ||
|
||
export { styles }; |