Skip to content

Commit

Permalink
bruh
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaynthakur committed Nov 4, 2023
1 parent 874347b commit 29b283b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app/(tabs)/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function HomeScreen() {
<Button title="Settings" />
</Link>
</View>
<Text style={styles.featuredSubheading}>Featured Stories</Text>
{/* <Text style={styles.featuredSubheading}>Featured Stories</Text>
<Text style={[globalStyles.body2, styles.featuredDescription]}>
Celebrate lorem ipsum by diving into related stories from our talented
authors.
Expand Down Expand Up @@ -96,7 +96,7 @@ function HomeScreen() {
image={story.image}
/>
))}
</ScrollView>
</ScrollView> */}
</ScrollView>
</SafeAreaView>
);
Expand Down
25 changes: 17 additions & 8 deletions src/app/auth/forgotPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { router } from 'expo-router';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { Alert, TextInput, View, StyleSheet } from 'react-native';
import { Button, Input } from 'react-native-elements';

import globalStyles from '../../styles/globalStyles';
import { useSession } from '../../utils/AuthContext';

function ForgotPasswordScreen() {
const { updateUser, signOut, resetPassword, verifyOtp } = useSession();
const {
updateUser,
signOut,
resetPassword,
verifyOtp,
isForgotPassword,
setIsForgotPassword,
} = useSession();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
Expand All @@ -18,30 +25,28 @@ function ForgotPasswordScreen() {
const { error } = await resetPassword(email);
if (error)
Alert.alert('Could not send a reset password email. Please try again.');
else
Alert.alert(
'Enter the verification code from your email to change your password',
);
else Alert.alert('isForgotPassword is:' + isForgotPassword);
};
const verifyCode = async () => {
setLoading(true);

if (email && verificationCode) {
console.log(
`isForgotPassword right before verifyOtp is: ${isForgotPassword}`,
);
const { error } = await verifyOtp(email, verificationCode);

if (error) {
Alert.alert(error.message);
setChangingPassword(false);
} else {
setChangingPassword(true);
router.replace('/auth/onboarding');
}
} else if (!verificationCode) {
Alert.alert(`Please enter a verification code`);
} else {
Alert.alert(`Please sign up again.`);
}

setLoading(false);
};

Expand All @@ -60,6 +65,10 @@ function ForgotPasswordScreen() {
setLoading(false);
};

useEffect(() => {
setIsForgotPassword(true);
}, []);

return (
<View style={globalStyles.auth_container}>
<View style={[globalStyles.verticallySpaced, globalStyles.mt20]}>
Expand Down
29 changes: 24 additions & 5 deletions src/utils/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface AuthState {
session: Session | null;
user: User | null;
isLoading: boolean;
isForgotPassword: boolean;
setIsForgotPassword: React.Dispatch<React.SetStateAction<boolean>>;
signIn: (newSession: Session | null) => void;
signUp: (email: string, password: string) => Promise<AuthResponse>;
signInWithEmail: (email: string, password: string) => Promise<AuthResponse>;
Expand Down Expand Up @@ -61,20 +63,35 @@ export function AuthContextProvider({
const [session, setSession] = useState<Session | null>(null);
const [user, setUser] = useState<User | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [isForgotPassword, setIsForgotPassword] = useState<boolean>(false);

useEffect(() => {
supabase.auth.getSession().then(({ data: { session: newSession } }) => {
setSession(newSession);
if (!isForgotPassword) {
setSession(newSession);
} else {
console.log(
`Did not set session after getSession because isForgotPassword is ${isForgotPassword}`,
);
}
});
// .finally(() => {
// setIsLoading(false);
// });

supabase.auth.onAuthStateChange((_event, newSession) => {
console.log(`This is the event: ${_event}`);
console.log(`This is the access token: ${newSession?.access_token}`);
console.log(`This is the refresh token: ${newSession?.refresh_token}`);
setSession(newSession);
if (!isForgotPassword) {
console.log(`forgot password is: ${isForgotPassword}`);
console.log(`This is the event: ${_event}`);
console.log(`This is the access token: ${newSession?.access_token}`);
console.log(`This is the refresh token: ${newSession?.refresh_token}`);
setSession(newSession);
} else {
setIsForgotPassword(false);
console.log(
`Did not set new session for event ${_event} because isForgotPassword is ${isForgotPassword}`,
);
}
});
}, []);

Expand Down Expand Up @@ -141,6 +158,8 @@ export function AuthContextProvider({
user,
session,
isLoading,
isForgotPassword,
setIsForgotPassword,
signUp,
signIn,
signInWithEmail,
Expand Down

0 comments on commit 29b283b

Please sign in to comment.