Skip to content

Commit

Permalink
Signing out of a profile using Firebase methods
Browse files Browse the repository at this point in the history
  • Loading branch information
EuJinnLucaShow committed Aug 24, 2023
1 parent 26fefa9 commit 9e54673
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 146 deletions.
15 changes: 15 additions & 0 deletions FirebaseConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';

const firebaseConfig = {
apiKey: 'AIzaSyBe9QUzhoIEVFB69Rqt8mMbjUwRxjO9KKg',
authDomain: 'web-app-b581f.firebaseapp.com',
projectId: 'web-app-b581f',
storageBucket: 'web-app-b581f.appspot.com',
messagingSenderId: '868623960717',
appId: '1:868623960717:web:e1dfe1b9f383dc100db0c4',
};

firebase.initializeApp(firebaseConfig);

export default firebase;
6 changes: 6 additions & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { getDefaultConfig } = require('@expo/metro-config');

const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.assetExts.push('cjs');

module.exports = defaultConfig;
471 changes: 356 additions & 115 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"web": "expo start --web"
},
"dependencies": {
"@react-native-async-storage/async-storage": "1.18.2",
"@react-navigation/bottom-tabs": "^6.5.8",
"@react-navigation/native": "^6.1.7",
"@react-navigation/native-stack": "^6.9.13",
Expand All @@ -24,12 +25,13 @@
"expo-status-bar": "~1.6.0",
"firebase": "^10.2.0",
"react": "18.2.0",
"react-native": "0.72.3",
"react-native": "0.72.4",
"react-native-maps": "^1.7.1",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-vector-icons": "^10.0.0",
"react-redux": "^8.1.2"
"react-redux": "^8.1.2",
"redux-persist": "^6.0.0"
},
"devDependencies": {
"@babel/core": "^7.20.0"
Expand Down
1 change: 1 addition & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const UseRoute = isAuth => {
</AuthStack.Navigator>
);
}

return (
<MainTab.Navigator
screenOptions={{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { authStateChange } from '../redux/auth/authOperations';

const Main = () => {
const { stateChange } = useSelector(state => state.auth);

console.log(stateChange);
const dispatch = useDispatch();

useEffect(() => {
Expand Down
16 changes: 0 additions & 16 deletions src/firebase/config.js

This file was deleted.

16 changes: 11 additions & 5 deletions src/redux/auth/authOperations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import db from '../../firebase/config';
import db from '../../../FirebaseConfig';
import { authSlice } from './authReducer';

const { updateUserProfile, authStateChangeUser, authSingOut } =
authSlice.actions;

export const authSingUp =
({ login, email, password }) =>
async (dispatch, getState) => {
Expand All @@ -17,7 +20,7 @@ export const authSingUp =
login: displayName,
};

dispatch(authSlice.actions.updateUserProfile(userUpdateProfile));
dispatch(updateUserProfile(userUpdateProfile));
} catch (error) {
console.log(error.message);
}
Expand All @@ -42,12 +45,15 @@ export const authStateChange = () => async (dispatch, getState) => {
userId: user.uid,
login: user.displayName,
};
dispatch(authSlice.actions.updateUserProfile(userUpdateProfile));
dispatch(authSlice.actions.authStateChange({ stateChange: true }));
dispatch(updateUserProfile(userUpdateProfile));
dispatch(authStateChangeUser({ stateChange: true }));
} else {
console.log('user is not logged in');
}
});
};

const authSingOut = () => async (dispatch, getState) => {};
export const authSingOutUser = () => async (dispatch, getState) => {
await db.auth().signOut();
dispatch(authSingOut());
};
15 changes: 9 additions & 6 deletions src/redux/auth/authReducer.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { createSlice } from '@reduxjs/toolkit';

const state = {
userId: null,
login: null,
stateChange: false,
};

export const authSlice = createSlice({
name: 'auth',
initialState: {
userId: null,
login: null,
stateChange: null,
},
initialState: state,
reducers: {
updateUserProfile: (state, { payload }) => ({
...state,
userId: payload.userId,
login: payload.login,
}),
authStateChange: (state, { payload }) => ({
authStateChangeUser: (state, { payload }) => ({
...state,
stateChange: payload.stateChange,
}),
authSingOut: () => state,
},
});
13 changes: 12 additions & 1 deletion src/screens/mainScreens/ProfileScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ import {
Image,
} from 'react-native';
import React from 'react';
import { useDispatch } from 'react-redux';
import { Feather, AntDesign } from '@expo/vector-icons';
import { authSingOutUser } from '../../redux/auth/authOperations';

export default function ProfileScreen() {
const dispatch = useDispatch();
const singOut = () => {
dispatch(authSingOutUser());
};

return (
<ImageBackground style={styles.imageBackground}>
<View style={styles.container}>
Expand All @@ -21,7 +28,11 @@ export default function ProfileScreen() {
</TouchableOpacity>
</View>
<Text style={styles.title}>Natali Romanova</Text>
<TouchableOpacity style={styles.logoutButton} activeOpacity={0.5}>
<TouchableOpacity
style={styles.logoutButton}
activeOpacity={0.5}
onPress={singOut}
>
<Feather name="log-out" size={25} color="gray" />
</TouchableOpacity>

Expand Down

0 comments on commit 9e54673

Please sign in to comment.