Skip to content

Commit 2bae82e

Browse files
authored
Merge pull request #164 from atlp-rwanda/ch-auth-ctxs
Feature: Implement Auth context to manage authentication everywhere.
2 parents dbd514d + 34c77db commit 2bae82e

15 files changed

+875
-306
lines changed

app/(app)/ActionMenu/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default function Index() {
6060
if (!fontsLoaded) {
6161
return null;
6262
}
63+
console.log(patientData?.image)
6364

6465

6566

app/(auth)/SignIn&SignOut/SetYourFingerPrint.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export default function SetYourFingerPrint() {
3535
<>
3636
<StatusBar style={theme === "light" ? "dark" : "light"} />
3737
<ScrollView
38-
style={{ flex: 1 }}
38+
style={{
39+
flex: 1,
40+
}}
3941
contentContainerStyle={{
4042
flexGrow: 1,
4143
paddingHorizontal: 20,

app/(auth)/SignIn&SignOut/SignInBlankForm.tsx

+74-63
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
Pressable,
1111
AppState,
1212
Alert,
13+
ActivityIndicator,
14+
ScrollView,
1315
} from "react-native";
1416
import { Ionicons } from "@expo/vector-icons";
1517
import CheckBox from "expo-checkbox";
@@ -20,12 +22,10 @@ import { Colors } from "../../../constants/Colors";
2022
import { ThemeContext } from "@/ctx/ThemeContext";
2123
import { SvgXml } from "react-native-svg";
2224
import {
23-
BackArrow,
2425
BlackApple,
2526
DarkContinueLine,
2627
LightContinueLine,
2728
WhiteApple,
28-
blackArrow,
2929
} from "@/components/Icons/Icons";
3030
import Alerts from "@/components/UI/AlertComponent";
3131
import { StatusBar } from "expo-status-bar";
@@ -34,6 +34,7 @@ import * as WebBrowser from "expo-web-browser";
3434
import * as Linking from "expo-linking";
3535
import { makeRedirectUri } from "expo-auth-session";
3636
import * as QueryParams from "expo-auth-session/build/QueryParams";
37+
import { useAuth } from "@/ctx/AuthContext";
3738

3839
WebBrowser.maybeCompleteAuthSession();
3940
const redirectTo = makeRedirectUri({
@@ -90,24 +91,21 @@ AppState.addEventListener("change", (state) => {
9091
});
9192

9293
const Login = () => {
93-
// const {login, loading} = useContext(AuthContext)
94-
94+
const { login } = useAuth();
9595
const [email, setEmail] = useState("");
9696
const [password, setPassword] = useState("");
97-
const [loading, setLoading] = useState(false);
97+
// const [loading, setLoading] = useState(false)
9898
const [secureTextEntry, setSecureTextEntry] = useState(true);
9999
const [isChecked, setIsChecked] = useState(false);
100100
const [emailFocused, setEmailFocused] = useState(false);
101101
const [passwordFocused, setPasswordFocused] = useState(false);
102102
const { theme, changeTheme } = useContext(ThemeContext);
103-
const [alert, setAlert] = useState<{ text: string, status: "success" | "error" | "info" | "warning" } | null>(null);
104-
const handleEmailChange = (text: string) => {
105-
setEmail(text);
106-
};
107103

108-
const handlePasswordChange = (text: string) => {
109-
setPassword(text);
110-
};
104+
const url = Linking.useURL();
105+
console.log({ url });
106+
if (url) createSessionFromUrl(url);
107+
108+
const [isLoading, setIsLoading] = useState(false);
111109

112110
const togglePasswordVisibility = () => {
113111
setSecureTextEntry(!secureTextEntry);
@@ -131,33 +129,36 @@ const Login = () => {
131129
setPasswordFocused(false);
132130
};
133131

134-
async function signInWithEmail(){
135-
setLoading(true)
136-
const{error} = await supabase.auth.signInWithPassword({
137-
email: email,
138-
password: password,
139-
})
140-
if (error) {
141-
setAlert({ text: "invalid email or password", status: "error" });
142-
setLoading(false);
143132

144-
} else {
145-
setAlert({ text: "login successfully", status: "success" });
146-
router.push('(app)/ActionMenu');
147-
setLoading(false);
148-
149-
}}
133+
async function signInWithEmail() {
134+
try {
135+
setIsLoading(true);
136+
await login(email, password);
137+
} catch (error) {
138+
Alert.alert("Error signing in");
139+
setIsLoading(false);
140+
}
141+
}
150142

151143
return (
152-
<View
153-
style={[
154-
styles.container,
155-
{ backgroundColor: theme === "dark" ? "#181A20" : "#FFFFFF" },
156-
]}
144+
<ScrollView
145+
style={{
146+
backgroundColor: theme === "dark" ? "#181A20" : "#FFFFFF",
147+
flex: 1,
148+
}}
149+
contentContainerStyle={{
150+
flexGrow: 1,
151+
justifyContent: "center",
152+
alignItems: "center",
153+
paddingTop: 24,
154+
paddingLeft: 24,
155+
paddingRight: 24,
156+
paddingBottom: 48,
157+
gap: 17,
158+
}}
157159
>
158-
159160
<StatusBar style={theme === "dark" ? "light" : "dark"} />
160-
161+
161162
<View>
162163
<Image source={require("../../../assets/icons/HeartPlus.png")} />
163164
</View>
@@ -171,7 +172,6 @@ async function signInWithEmail(){
171172
>
172173
Login to Your Account
173174
</Text>
174-
{alert && <Alerts text={alert.text} status={alert.status} />}
175175
</View>
176176

177177
<View style={styles.Buttons}>
@@ -190,7 +190,14 @@ async function signInWithEmail(){
190190
style={[styles.icon, emailFocused && styles.iconFocused]}
191191
/>
192192
<TextInput
193-
style={[{fontSize: 16,flex: 1,color: theme === "dark"? Colors.grayScale._50 : "black"}, emailFocused && styles.emailFocused]}
193+
style={[
194+
{
195+
fontSize: 16,
196+
flex: 1,
197+
color: theme === "dark" ? Colors.grayScale._50 : "black",
198+
},
199+
emailFocused && styles.emailFocused,
200+
]}
194201
placeholder="Email"
195202
keyboardType="email-address"
196203
placeholderTextColor="#9E9E9E"
@@ -217,7 +224,14 @@ async function signInWithEmail(){
217224
/>
218225

219226
<TextInput
220-
style={[{fontSize: 16,flex: 1,color: theme === "dark"? Colors.grayScale._50 : "black"}, passwordFocused && styles.emailFocused]}
227+
style={[
228+
{
229+
fontSize: 16,
230+
flex: 1,
231+
color: theme === "dark" ? Colors.grayScale._50 : "black",
232+
},
233+
passwordFocused && styles.emailFocused,
234+
]}
221235
placeholder="Password"
222236
placeholderTextColor="#9E9E9E"
223237
secureTextEntry={secureTextEntry}
@@ -262,13 +276,28 @@ async function signInWithEmail(){
262276
</View>
263277

264278
<View>
265-
<TouchableOpacity
266-
disabled={loading}
279+
<Pressable
280+
disabled={isLoading}
267281
onPress={() => signInWithEmail()}
268-
style={styles.signinBtn}
282+
style={{
283+
backgroundColor: isLoading
284+
? Colors.status.disabled_button
285+
: Colors.main.primary._500,
286+
width: 360,
287+
height: 58,
288+
borderRadius: 100,
289+
justifyContent: "center",
290+
alignItems: "center",
291+
shadowColor: "#246BFD",
292+
elevation: 10,
293+
}}
269294
>
270-
<Text style={styles.signText}>Sign in</Text>
271-
</TouchableOpacity>
295+
{isLoading ? (
296+
<ActivityIndicator color="white" />
297+
) : (
298+
<Text style={styles.signText}>Sign in</Text>
299+
)}
300+
</Pressable>
272301
</View>
273302

274303
<TouchableOpacity
@@ -353,12 +382,10 @@ async function signInWithEmail(){
353382
Sign up
354383
</Text>
355384
</View>
356-
</View>
385+
</ScrollView>
357386
);
358387
};
359388

360-
export default Login;
361-
362389
const styles = StyleSheet.create({
363390
inputOneFocused: {
364391
borderColor: "#246BFD",
@@ -455,16 +482,6 @@ const styles = StyleSheet.create({
455482
color: "#FFFFFF",
456483
fontWeight: "bold",
457484
},
458-
signinBtn: {
459-
backgroundColor: "#246BFD",
460-
width: 360,
461-
height: 58,
462-
borderRadius: 100,
463-
justifyContent: "center",
464-
alignItems: "center",
465-
shadowColor: "#246BFD",
466-
elevation: 10,
467-
},
468485
textBtn: {
469486
fontSize: 16,
470487
fontWeight: "bold",
@@ -510,17 +527,11 @@ const styles = StyleSheet.create({
510527
},
511528
container: {
512529
flex: 1,
513-
flexDirection: "column",
514-
justifyContent: "center",
515-
alignItems: "center",
516-
gap: 17,
517-
paddingTop: 24,
518-
paddingLeft: 24,
519-
paddingBottom: 48,
520-
paddingRight: 24,
521530
},
522531
LoginText: {
523532
color: "#246BFD",
524533
fontWeight: "600",
525534
},
526535
});
536+
537+
export default Login;

0 commit comments

Comments
 (0)