Skip to content

Commit

Permalink
Merge pull request #93 from ReCoded-Org/i90-switching_to_firebase
Browse files Browse the repository at this point in the history
I90 switching to firebase
  • Loading branch information
gizemhaspolat authored Aug 29, 2022
2 parents 219fb38 + efcde3e commit 803153a
Show file tree
Hide file tree
Showing 15 changed files with 2,592 additions and 365 deletions.
55 changes: 55 additions & 0 deletions context/AuthContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { auth } from "firebase.config";
import {
createUserWithEmailAndPassword,
onAuthStateChanged,
signInWithEmailAndPassword,
signOut,
} from "firebase/auth";
import { createContext, useContext, useEffect, useState } from "react";
// import { auth } from '../config/firebase'

const AuthContext = createContext({});

export const useAuth = () => useContext(AuthContext);

export const AuthContextProvider = ({ children }) => {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
// console.log(user);

useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
if (user) {
setUser({
uid: user.uid,
email: user.email,
displayName: user.displayName,
});
} else {
setUser(null);
}
setLoading(false);
});

return () => unsubscribe();
}, []);

const signup = (email, password) => {
return createUserWithEmailAndPassword(auth, email, password);
};

const login = (email, password) => {
return signInWithEmailAndPassword(auth, email, password);
};

const logout = async () => {
setUser(null);
await signOut(auth);
};

return (
<AuthContext.Provider value={{ user, login, signup, logout }}>
{loading ? null : children}
</AuthContext.Provider>
);
};
20 changes: 9 additions & 11 deletions data/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"id": 1,
"title": "Apple iPad Pro",
"description": "With the power of Apple Pencil, iPad Pro transforms into an immersive drawing canvas and the world's best note‑taking device.",
"coverImage": "https://scontent.fist2-4.fna.fbcdn.net/v/t45.5328-4/279890261_5436365223110547_954052529167996794_n.jpg?stp=dst-jpg_s960x960&_nc_cat=109&ccb=1-7&_nc_sid=c48759&_nc_ohc=0sd1VeqW02IAX8A5Ac1&_nc_ht=scontent.fist2-4.fna&oh=00_AT-h-jQVp_1_JcifoK7L8db4BEOYn3f4pnCO6gPYxagTpQ&oe=630C0797",
"coverImage": "https://cdn.pocket-lint.com/r/s/1200x/assets/images/151545-tablets-review-apple-ipad-pro-129-inch-2020-review-business-as-usual-image1-buq5ipfo1e.jpg",
"otherImages": [
"https://scontent.fist2-3.fna.fbcdn.net/v/t45.5328-4/284824987_5338950829484855_214780658760877871_n.jpg?stp=dst-jpg_s960x960&_nc_cat=104&ccb=1-7&_nc_sid=c48759&_nc_ohc=M-gQTAS1z7kAX-MVi4X&_nc_ht=scontent.fist2-3.fna&oh=00_AT94IYmDMO2vwJ_ObSw94xbw-VRjYp3yTVCgZx89ZfyorA&oe=630D7358",
"https://scontent.fist2-3.fna.fbcdn.net/v/t45.5328-4/285063090_5668607753171025_7732982259692423018_n.jpg?stp=dst-jpg_s960x960&_nc_cat=108&ccb=1-7&_nc_sid=c48759&_nc_ohc=2MPGM71oJYoAX8mn3Z6&_nc_ht=scontent.fist2-3.fna&oh=00_AT-4obxvIQLeNRiHBW8RW8co5vrDgRfC3xOTiIZwxhOOGQ&oe=630CE122",
"https://scontent.fist2-3.fna.fbcdn.net/v/t45.5328-4/280158561_5253591094724942_2525581837010045055_n.jpg?stp=dst-jpg_p720x720&_nc_cat=108&ccb=1-7&_nc_sid=c48759&_nc_ohc=Wk83ay4TvEMAX9L2yBd&_nc_ht=scontent.fist2-3.fna&oh=00_AT8lel8EnFeimYYTS5uKopJ5T2N0MnWNfHj6JyIYaUlYJw&oe=630BC934"
"https://scontent.fist2-3.fna.fbcdn.net/v/t45.5328-4/285063090_5668607753171025_7732982259692423018_n.jpg?stp=dst-jpg_s960x960&_nc_cat=108&ccb=1-7&_nc_sid=c48759&_nc_ohc=2MPGM71oJYoAX8mn3Z6&_nc_ht=scontent.fist2-3.fna&oh=00_AT-4obxvIQLeNRiHBW8RW8co5vrDgRfC3xOTiIZwxhOOGQ&oe=630CE122"
],
"price": 4000,
"category": "Electronics",
Expand Down Expand Up @@ -236,11 +235,11 @@
"id": 9,
"title": "PS5",
"description": "Merhabalar cihazım ps5 sıfır cd sürüm modeli olup en son seri Olan 1116-a serisidir.cihaz İrlandadan alınmış olup faturası mevcuttur.1 yıl garantisi vardır Sony. Cihaz tek kol ile gelmektedir.isterseniz ekstradan ikinci kol aksesuar veya oyunlar alabilirsiniz.cihazı dükkanımıza gelip görüp deneyip alabilirsiniz.takas sadece Ps4 modelleri ve Xbox series s ile olur. Takas ve diğer sorularınız İçin bizimle iletişime geçebilirsiniz.",
"coverImage": "https://scontent.fist2-3.fna.fbcdn.net/v/t45.5328-4/270323703_4697050520409634_5109816706231578145_n.jpg?stp=dst-jpg_p180x540&_nc_cat=106&ccb=1-7&_nc_sid=c48759&_nc_ohc=V1H8nhemLzcAX-Cz21Q&_nc_ht=scontent.fist2-3.fna&oh=00_AT8QAywp0d2rFCwvPM1GvvhdlGCGbv8ExJ28yKUeDJdoLA&oe=630BD883",
"coverImage": "https://rankiing.net/wp-content/uploads/2021/08/Can-ExpressVPN-be-used-on-ps5.jpg",
"otherImages": [
"https://scontent.fist2-4.fna.fbcdn.net/v/t45.5328-4/279133456_5749902745130897_8424270164892740188_n.jpg?stp=dst-jpg_p720x720&_nc_cat=109&ccb=1-7&_nc_sid=c48759&_nc_ohc=bMQqCY6pVq0AX-lUL-Z&_nc_ht=scontent.fist2-4.fna&oh=00_AT_08-Blo1bKuu39aimnos5w7khOjVCb40WmPP3zxuynGw&oe=630C2D92",
"https://scontent.fist2-4.fna.fbcdn.net/v/t45.5328-4/300143038_4692930854143374_3086793362286115740_n.jpg?stp=dst-jpg_p180x540&_nc_cat=111&ccb=1-7&_nc_sid=c48759&_nc_ohc=IBx0Rz2pLAUAX9BmIdg&_nc_ht=scontent.fist2-4.fna&oh=00_AT9NcKEykTZ11mlWiupTn_7TtY0ibFjwdyJnYZ7CBz3OiA&oe=630C6952",
"https://scontent.fist2-3.fna.fbcdn.net/v/t45.5328-4/284979969_5314023665299855_2904224700535153419_n.jpg?_nc_cat=103&ccb=1-7&_nc_sid=c48759&_nc_ohc=GdCGsb6RfikAX8Ht9q2&tn=o1n-iYo_c7xaIWX5&_nc_ht=scontent.fist2-3.fna&oh=00_AT-zjKN62EL2us8sBrRGfTOqfpfD9BB3LlFPjpI3EYJo-A&oe=630D00C2"
"https://cdn.vox-cdn.com/thumbor/JQUrCP399QDuuRtqJvK2wEnuBbc=/1400x1400/filters:format(jpeg)/cdn.vox-cdn.com/uploads/chorus_asset/file/21990360/vpavic_4261_20201023_0020.jpg",
"https://preview.redd.it/ifgvhy3m2t861.jpg?width=640&crop=smart&auto=webp&s=5e57a29b5b2cb1dc98aadd83522f94defe9bd542",
"https://external-preview.redd.it/HnujB8Z4RqKXUIq4FqhErGRcQEuJXww2hRkD4iFF378.jpg?auto=webp&s=f06b5dc197b57ab031640a71f117348017538305"
],
"price": 14000,
"category": "Electronics",
Expand Down Expand Up @@ -584,11 +583,10 @@
"id": 21,
"title": "Foldable Bike",
"description": "20 AY GARANTİSİ DEVAM EDİYOR TAM DOLU AKÜ İLE 50 KM YOL GİDİYOR 35 KM HIZ YAPIYOR 20 İNÇ JANT İLE YETİŞKİNLER İÇİN UYGUNDUR TAKAS DÜŞÜNMÜYORUM ALİCİSİNA HAYİRLİ OLSUN",
"coverImage": "https://scontent.fist2-3.fna.fbcdn.net/v/t39.30808-6/300681616_180369751145336_614853087043685303_n.jpg?_nc_cat=106&ccb=1-7&_nc_sid=843cd7&_nc_ohc=_eR2Jcxi85MAX_UGTyY&_nc_ht=scontent.fist2-3.fna&oh=00_AT9iOeWVvs-PDR_BFDt1WcNgTXfitwXPJrzpIxvL40Ph2Q&oe=630BBEBF",
"coverImage": "https://media.karousell.com/media/photos/products/2020/8/3/folding_bike_pacific_reach_1596443153_4dc51479",
"otherImages": [
"https://scontent.fist2-3.fna.fbcdn.net/v/t39.30808-6/300855323_180370057811972_3532234012927148499_n.jpg?_nc_cat=104&ccb=1-7&_nc_sid=843cd7&_nc_ohc=n36D_Eg1R4oAX81kWxD&tn=o1n-iYo_c7xaIWX5&_nc_ht=scontent.fist2-3.fna&oh=00_AT9AXqmSX7dluskBm7T6EmoyZC43tRc-rGiPLBrYJpx4Wg&oe=630CDD31",
"https://scontent.fist2-4.fna.fbcdn.net/v/t39.30808-6/300387728_180370087811969_8536663198367119878_n.jpg?_nc_cat=111&ccb=1-7&_nc_sid=843cd7&_nc_ohc=kvaYNNomXWMAX8M0HZa&tn=o1n-iYo_c7xaIWX5&_nc_ht=scontent.fist2-4.fna&oh=00_AT--9w49Orm3kq79w_y3tEKjUxXeJbcU89rMjqjl5W_wDg&oe=630BAA1D",
"https://scontent.fist2-3.fna.fbcdn.net/v/t39.30808-6/300592377_180369064478738_3377704661137825581_n.jpg?_nc_cat=104&ccb=1-7&_nc_sid=843cd7&_nc_ohc=pOC1YohW7TYAX8YyvYq&tn=o1n-iYo_c7xaIWX5&_nc_ht=scontent.fist2-3.fna&oh=00_AT_hcr-fLpFWVyPh45oj4b5RbVljllV2fejfGd3xwoGK9A&oe=630D78FA"
"https://media.karousell.com/media/photos/products/2020/8/3/folding_bike_pacific_reach_1596443154_172c9bfd_progressive",
"https://media.karousell.com/media/photos/products/2020/8/3/folding_bike_pacific_reach_1596443154_47d707d5_progressive"
],
"price": 4400,
"category": "Two-wheeler",
Expand Down
16 changes: 16 additions & 0 deletions firebase.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable unused-imports/no-unused-vars */
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

const firebaseConfig = {
apiKey: "AIzaSyC0zI86ZYBP-xrPj5jiydZw4bKuEPx-vXU",
authDomain: "student-store-7cf9c.firebaseapp.com",
projectId: "student-store-7cf9c",
storageBucket: "student-store-7cf9c.appspot.com",
messagingSenderId: "604088151357",
appId: "1:604088151357:web:54360215fa3b0cc4fb6954",
measurementId: "G-6RJH6GQHKG",
};

const app = initializeApp(firebaseConfig);
export const auth = getAuth();
Loading

0 comments on commit 803153a

Please sign in to comment.