Skip to content

Commit

Permalink
Added basic authentication
Browse files Browse the repository at this point in the history
Uses email but login is replaced with anonymous auth
  • Loading branch information
jsakeag committed Oct 31, 2022
1 parent a89e3cd commit 90c8c74
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 22 deletions.
1 change: 1 addition & 0 deletions assets/animations/join-background.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"4.6.10","fr":15,"ip":0,"op":155,"w":1080,"h":1920,"nm":"background","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[540,960,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[1160,880]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect"},{"ty":"st","c":{"a":0,"k":[0.9960784,0.7843137,0.145098,1]},"o":{"a":0,"k":100},"w":{"a":0,"k":6},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke"},{"ty":"gf","o":{"a":0,"k":100},"r":1,"g":{"p":3,"k":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[0,0.511,0.89,0.283,0.5,0.334,0.873,0.583,1,0.156,0.857,0.882],"e":[0,0.726,0.283,0.89,0.5,0.441,0.356,0.886,1,0.156,0.429,0.882]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":31,"s":[0,0.726,0.283,0.89,0.5,0.441,0.356,0.886,1,0.156,0.429,0.882],"e":[0,0.89,0.283,0.283,0.5,0.886,0.553,0.219,1,0.882,0.823,0.156]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":61,"s":[0,0.89,0.283,0.283,0.5,0.886,0.553,0.219,1,0.882,0.823,0.156],"e":[0,0,0.312,0.737,0.5,0.078,0.597,0.754,1,0.156,0.882,0.771]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":91,"s":[0,0,0.312,0.737,0.5,0.078,0.597,0.754,1,0.156,0.882,0.771],"e":[0,0.51,0.89,0.282,0.5,0.333,0.873,0.582,1,0.157,0.855,0.882]},{"t":120}]}},"s":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[-430.769,-404.573],"e":[23.726,-364.48],"to":[75.7491683959961,6.68213844299316],"ti":[-123.915840148926,-8.51547145843506]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":31,"s":[23.726,-364.48],"e":[312.726,-353.48],"to":[123.915840148926,8.51547145843506],"ti":[-1.00208830833435,-1.83333337306976]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":61,"s":[312.726,-353.48],"e":[29.739,-353.48],"to":[1.00208830833435,1.83333337306976],"ti":[120.055290222168,0.60746711492538]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":91,"s":[29.739,-353.48],"e":[-407.606,-357.125],"to":[-120.055290222168,-0.60746711492538],"ti":[72.8907089233398,0.60746711492538]},{"t":120}]},"e":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[374.412,342.611],"e":[22.822,357.191],"to":[-58.5984153747559,2.42986845970154],"ti":[132.520950317383,-7.89707231521606]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":31,"s":[22.822,357.191],"e":[-420.714,389.994],"to":[-132.520950317383,7.89707231521606],"ti":[-4.68509674072266,-7.89707231521606]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":61,"s":[-420.714,389.994],"e":[50.932,404.573],"to":[4.68509674072266,7.89707231521606],"ti":[-132.918350219727,4.25226974487305]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":91,"s":[50.932,404.573],"e":[376.797,364.48],"to":[132.918350219727,-4.25226974487305],"ti":[-54.3107261657715,6.68213844299316]},{"t":120}]},"t":1,"nm":"Gradient Fill 1","mn":"ADBE Vector Graphic - G-Fill"},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[93.29,219.491],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group"}],"ip":0,"op":155,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":2,"ty":1,"nm":"Deep Red Solid 1","ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[540,960,0]},"a":{"a":0,"k":[540,960,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"sw":1080,"sh":1920,"sc":"#be2a2a","ip":0,"op":155,"st":0,"bm":0,"sr":1}]}
4 changes: 3 additions & 1 deletion components/HomeText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { View, Text } from "react-native";
import React from "react";
import firebase from "../firebase";

export default function HomeText() {
return (
Expand All @@ -12,7 +13,8 @@ export default function HomeText() {
}}
>
<Text style={{ textAlign: "center" }}>
search for restaurants then suggest them by pressing the checkbox!
search for restaurants then suggest them by pressing the checkbox! Your
user ID: {firebase.auth().currentUser?.uid}
</Text>
</View>
);
Expand Down
1 change: 0 additions & 1 deletion components/SearchItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { View, Text, Image, TouchableOpacity } from "react-native";
import RestaurantDetail from "../screens/RestaurantDetail";
import BouncyCheckbox from "react-native-bouncy-checkbox";
import { useDispatch } from "react-redux";
import { useSelector } from "react-redux";

//isChecked is set to this. no hook but updates when refresh
{
Expand Down
45 changes: 45 additions & 0 deletions components/join/HeaderTabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useState } from "react";
import { View, Text, TouchableOpacity } from "react-native";

export default function HeaderTabs(props) {
return (
<View style={{ flexDirection: "row", alignSelf: "center" }}>
<HeaderButton
text="Join"
btnColor="black"
textColor="white"
activeTab={props.activeTab}
setActiveTab={props.setActiveTab}
/>
<HeaderButton
text="Create"
btnColor="white"
textColor="black"
activeTab={props.activeTab}
setActiveTab={props.setActiveTab}
/>
</View>
);
}

const HeaderButton = (props) => (
<TouchableOpacity
style={{
backgroundColor: props.activeTab === props.text ? "#bbb" : "white",
paddingVertical: 6,
paddingHorizontal: 16,
borderRadius: 30,
}}
onPress={() => props.setActiveTab(props.text)}
>
<Text
style={{
color: props.activeTab === props.text ? "white" : "#bbb",
fontSize: 15,
fontWeight: "900",
}}
>
{props.text}
</Text>
</TouchableOpacity>
);
1 change: 1 addition & 0 deletions firebase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import firebase from "firebase/compat/app";
import "firebase/compat/firestore";
import "firebase/compat/auth";

const firebaseConfig = {
//databaseURL: "https://decide-app-no-billing-8385f.firebaseio.com",
Expand Down
4 changes: 3 additions & 1 deletion navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import RestaurantDetail from "./screens/RestaurantDetail";
import { Provider as ReduxProvider } from "react-redux";
import configureStore from "./redux/store";
import ChoiceFound from "./screens/ChoiceFound";
import Join from "./screens/Join";
//import Search from "./screens/Search";

const store = configureStore();
Expand All @@ -20,7 +21,8 @@ export default function RootNavigation() {
return (
<ReduxProvider store={store}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Home" screenOptions={screenOptions}>
<Stack.Navigator initialRouteName="Join" screenOptions={screenOptions}>
<Stack.Screen name="Join" component={Join} />
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="RestaurantDetail" component={RestaurantDetail} />
<Stack.Screen name="ChoiceFound" component={ChoiceFound} />
Expand Down
32 changes: 14 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"react-redux": "^8.0.4",
"reanimated-bottom-sheet": "^1.0.0-alpha.22",
"redux": "^4.2.0",
"tslib": "^2.4.0"
"tslib": "^2.4.0",
"react-native-screens": "~3.15.0",
"react-native-safe-area-context": "4.3.1"
},
"devDependencies": {
"@babel/core": "^7.18.6"
Expand Down
168 changes: 168 additions & 0 deletions screens/Join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import {
KeyboardAvoidingView,
StyleSheet,
Text,
TextInput,
View,
TouchableOpacity,
SafeAreaView,
} from "react-native";
import React, { useEffect, useState } from "react";
import firebase from "../firebase";
import LottieView from "lottie-react-native";
import HeaderTabs from "../components/join/HeaderTabs";

const Join = ({ navigation }) => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [activeTab, setActiveTab] = useState("Join");

const auth = firebase.auth();

useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((user) => {
if (user) {
navigation.replace("Home");
}
});

return unsubscribe;
}, []);

const handleSignUp = () => {
auth
.createUserWithEmailAndPassword(email, password)
.then((userCredentials) => {
const user = userCredentials.user;
console.log("Registered with:", user.email);
})
.catch((error) => alert(error.message));
};

const loginAnonymously = () => {
auth
.signInAnonymously()
.then((userCredentials) => {
const user = userCredentials.user;
console.log("Logged in as user ", user.uid);
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
};

const generateCode = () => {
let code = "";
let letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (let i = 0; i < 4; i++) {
code += letters[Math.floor(Math.random() * letters.length)];
}
return code;
};

const code = gemerateCode();

return (
<>
<LottieView
style={{
height: 100,
alignSelf: "center",
marginBottom: 30,
position: "absolute",
height: "101%",
width: "101%",
opacity: 0.7,
}}
source={require("../assets/animations/join-background.json")}
autoPlay
speed={1}
loop={false}
/>
<SafeAreaView>
<HeaderTabs activeTab={activeTab} setActiveTab={setActiveTab} />
</SafeAreaView>
<KeyboardAvoidingView style={styles.container} behavior="padding">
<View style={styles.inputContainer}>
<TextInput
placeholder="Email"
placeholderTextColor="#aaa"
value={email}
onChangeText={(text) => setEmail(text)}
style={styles.input}
/>
<TextInput
placeholder="Password"
placeholderTextColor="#aaa"
value={password}
onChangeText={(text) => setPassword(text)}
style={styles.input}
secureTextEntry
/>
</View>

<View style={styles.buttonContainer}>
<TouchableOpacity onPress={loginAnonymously} style={styles.button}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={handleSignUp}
style={[styles.button, styles.buttonOutline]}
>
<Text style={styles.buttonOutlineText}>Register</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
</>
);
};
export default Join;

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
inputContainer: {
width: "80%",
},
input: {
backgroundColor: "white",
paddingHorizontal: 15,
paddingVertical: 10,
borderRadius: 10,
marginTop: 5,
},
buttonContainer: {
width: "60%",
justifyContent: "center",
alignItems: "center",
marginTop: 40,
},
button: {
backgroundColor: "#0782F9",
width: "100%",
padding: 15,
borderRadius: 10,
alignItems: "center",
},
buttonOutline: {
backgroundColor: "white",
marginTop: 5,
borderColor: "#0782F9",
borderWidth: 2,
},
buttonText: {
color: "white",
fontWeight: "700",
fontSize: 16,
},
buttonOutlineText: {
color: "#0782F9",
fontWeight: "700",
fontSize: 16,
},
});

0 comments on commit 90c8c74

Please sign in to comment.