Skip to content

Commit

Permalink
fix(signout): fix Import && restore button icon
Browse files Browse the repository at this point in the history
Co-authored-by: Kübra Demirhan <[email protected]>
Signed-off-by: Abderrahmane Bennani <[email protected]>
  • Loading branch information
AbderrahmaneBennani and kuebrademirhan committed Feb 3, 2025
1 parent 621b983 commit 8b36b2b
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 175 deletions.
47 changes: 26 additions & 21 deletions app/src/components/SignOutButton.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import { useNavigation } from '@react-navigation/native';
import { Button, Text } from '@shadcn/components';
import { Screens, Stacks, fireAuth } from '@src/constants';
import type { AppNavigation } from '@src/types';
import Constants from 'expo-constants';
import { signOut } from 'firebase/auth';
import { View } from 'react-native';
import { GoogleSignin } from "@react-native-google-signin/google-signin";
import { useNavigation } from "@react-navigation/native";
import { Button, Text } from "@shadcn/components";
import { Screens, Stacks, fireAuth } from "@src/constants";
import type { AppNavigation } from "@src/types";
import Constants from "expo-constants";
import { signOut } from "firebase/auth";
import { DoorOpen } from "lucide-react-native";
import { View } from "react-native";

export const SignOutButton: React.FC = () => {
const { reset } = useNavigation<AppNavigation>();
Expand All @@ -14,29 +15,29 @@ export const SignOutButton: React.FC = () => {
try {
GoogleSignin.configure({
webClientId: Constants.expoConfig?.extra?.googleAuthClientId,
offlineAccess: true
offlineAccess: true,
});

// Check if a user is signed in
if (!fireAuth.currentUser) {
console.log('No user is currently signed in.');
console.log("No user is currently signed in.");
return;
}

// Check if the user is signed in with Google
const isGoogleUser = fireAuth.currentUser.providerData.some(
(provider) => provider.providerId === 'google.com'
(provider) => provider.providerId === "google.com"
);
console.log('Is Google User:', isGoogleUser);
console.log("Is Google User:", isGoogleUser);

// Sign out from Google if applicable
if (isGoogleUser) {
await GoogleSignin.signOut();
console.log('Google sign-out successful');
console.log("Google sign-out successful");
} else {
// Sign out from Firebase
await signOut(fireAuth);
console.log('Firebase sign-out successful');
console.log("Firebase sign-out successful");
}

// Reset navigation to SignIn screen
Expand All @@ -45,19 +46,23 @@ export const SignOutButton: React.FC = () => {
routes: [
{
name: Stacks.UnAuth,
params: { screen: Screens.SignIn }
}
]
params: { screen: Screens.SignIn },
},
],
});
} catch (error) {
console.error('Logout error:', error);
console.error("Logout error:", error);
}
};

return (
<View className='flex w-full justify-center mt-6 mb-2'>
<Button className='w-1/3' onPress={handleLogout}>
<Text>Log Out</Text>
<View className="w-full flex flex-row justify-start mt-6 mb-2">
<Button
className="bg-white border border-primary flex flex-row gap-x-3"
onPress={handleLogout}
>
<DoorOpen size={18} className="text-primary" />
<Text className="text-primary">Logout</Text>
</Button>
</View>
);
Expand Down
Loading

0 comments on commit 8b36b2b

Please sign in to comment.