Advertisement
Fahim_7861

Untitled

Jul 16th, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.13 KB | None | 0 0
  1. import React, { useState } from 'react'
  2.  
  3. import firebase from "firebase/app";
  4. import "firebase/auth";
  5.  
  6.  
  7. import firebaseConfig from './firebase.confiq'
  8. // import google from '../../images/google.png'
  9. // import facebook from '../../images/facebook.png'
  10.  
  11. // import { ClearUserInfo, InsertUserInfo } from '../../Utilities/SessionData';
  12.  
  13.  
  14. import { useHistory, useLocation } from 'react-router-dom';
  15. import { useDispatch } from 'react-redux';
  16. import { authAction } from '../../redux/actions/authAction';
  17. // import {AiFillTag} from "react-icons/ai";
  18. // import {FaFacebook} from "react-icons/fa";
  19. // import {FcGoogle} from "react-icons/fc";
  20.  
  21.  
  22.  
  23.  
  24.  
  25. if (!firebase.apps.length) firebase.initializeApp(firebaseConfig);
  26.  
  27.  
  28. export const handleSignOut = () => {
  29.  
  30. firebase.auth().signOut()
  31. .then(result => {
  32.  
  33. alert('sign out')
  34.  
  35.  
  36.  
  37. }).catch(error => console(error, error.message));
  38.  
  39.  
  40. }
  41.  
  42.  
  43. const Login = () => {
  44.  
  45. const dispatch = useDispatch();
  46.  
  47.  
  48. const googleProvider = new firebase.auth.GoogleAuthProvider();
  49.  
  50. const fbProvider = new firebase.auth.FacebookAuthProvider();
  51.  
  52. // const history=useHistory();
  53.  
  54. const [userInformation,setUserInformation]=useState({
  55.  
  56.  
  57.  
  58.  
  59. });
  60.  
  61. // const location=useLocation();
  62.  
  63. // let {from}=location.state || {from :{pathname:'/home'}};
  64.  
  65.  
  66. const [loginUser,setLoginUser]=useState({});
  67.  
  68. const LoginCheck=(email)=>
  69. {
  70.  
  71. //console.log(email,typeof(email));
  72.  
  73.  
  74. // history.replace(from);
  75.  
  76.  
  77. }
  78.  
  79. const handleGoogleSignInUp = async () => {
  80.  
  81. try{
  82.  
  83. const result = await firebase.auth().signInWithPopup(googleProvider);
  84.  
  85. console.log(1,result.user);
  86.  
  87. console.log('Fasiodfkasdlfkasdlfkad')
  88.  
  89. const {displayName,email,photoURL} = result.user;
  90.  
  91.  
  92. const data ={
  93. name :displayName,
  94. email : email,
  95. pic : photoURL
  96. }
  97. console.log(data)
  98.  
  99. dispatch(authAction(data));
  100.  
  101.  
  102.  
  103.  
  104. }
  105.  
  106. catch(err)
  107. {
  108.  
  109. console.log(2, err)
  110.  
  111. }
  112.  
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119. const handleFbSignIn=()=>{
  120.  
  121. firebase.auth().signInWithPopup(fbProvider).then(function(result) {
  122.  
  123.  
  124.  
  125. const {displayName,email,photoURL} = result.user;
  126.  
  127.  
  128. const data ={
  129. name :displayName,
  130. email : email,
  131. pic : photoURL
  132. }
  133. console.log(data)
  134.  
  135. dispatch(authAction(data));
  136. // history.push('/home');
  137.  
  138. // window.location.reload(false);
  139.  
  140.  
  141.  
  142.  
  143.  
  144. }).catch(function(error) {
  145.  
  146.  
  147.  
  148. console.log(2,error);
  149.  
  150. });
  151.  
  152. }
  153.  
  154.  
  155.  
  156. // const handleBlurSignUp = (event) => {
  157.  
  158.  
  159. // let isFieldValid = true;
  160.  
  161. // if (event.target.name === 'email') {
  162.  
  163. // //console.log(event.target.value);
  164. // const isEmailValid = /\S+@\S+\.\S+/
  165.  
  166. // isFieldValid &= isEmailValid.test(event.target.value);
  167.  
  168. // // console.log(isEmailValid.test(event.target.value));
  169. // }
  170. // else if (event.target.name === 'password') {
  171.  
  172. // const isPasswordValid = event.target.value.length > 6;
  173.  
  174. // const passHasNumber = /\d{1}/.test(event.target.value);
  175.  
  176.  
  177. // if(!isPasswordValid && !passHasNumber)
  178. // swal('Your password should contain at least seven characters and one digit');
  179. // else if(isPasswordValid==false)
  180. // swal('Your password should contain at least seven characters');
  181.  
  182. // else if(passHasNumber==false)
  183. // swal('Your password shoould contain minimum one digit');
  184.  
  185.  
  186.  
  187. // isFieldValid &= isPasswordValid && passHasNumber;
  188.  
  189. // // console.log(isPasswordValid&&passHasNumber);
  190. // }
  191.  
  192.  
  193.  
  194. // if (isFieldValid) {
  195. // const newUserInfo = { ...userInformation };
  196.  
  197. // newUserInfo[event.target.name] = event.target.value;
  198.  
  199. // console.log(newUserInfo,event.target.name,event.target.value);
  200.  
  201. // setUserInformation(newUserInfo);
  202. // }
  203.  
  204.  
  205.  
  206.  
  207.  
  208. // }
  209.  
  210. // const handleBlurSignIn=(event)=>
  211. // {
  212. // const newUserInfo = { ...loginUser };
  213.  
  214. // newUserInfo[event.target.name] = event.target.value;
  215.  
  216.  
  217. // setLoginUser(newUserInfo);
  218. // }
  219.  
  220. // const signupForm=(e)=>
  221. // {
  222.  
  223. // console.log(1,userInformation);
  224.  
  225. // if (userInformation.displayName && userInformation.email && userInformation.password) {
  226.  
  227.  
  228. // firebase.auth().createUserWithEmailAndPassword(userInformation.email, userInformation.password)
  229. // .then(res => {
  230.  
  231.  
  232. // updateUserName(userInformation.displayName)
  233.  
  234.  
  235.  
  236.  
  237. // })
  238. // .catch((error) => {
  239.  
  240. // swal('already have a account');
  241.  
  242.  
  243.  
  244.  
  245. // });
  246. // }
  247.  
  248. // e.preventDefault();
  249.  
  250.  
  251. // }
  252.  
  253. // const ChangeSignUpForm=()=>
  254. // {
  255.  
  256. // const container = document.getElementById('container');
  257. // container.classList.add("right-panel-active");
  258.  
  259. // }
  260.  
  261.  
  262. // function updateUserName(name) {
  263.  
  264. // var user = firebase.auth().currentUser;
  265.  
  266.  
  267. // user.updateProfile({
  268. // displayName: name,
  269.  
  270. // }).then(function () {
  271. // swal("Congratulation!", "You Are Successfully Registered!", "success");
  272.  
  273. // ChangeSignInForm();
  274.  
  275.  
  276.  
  277. // }).catch(function (error) {
  278. // console.log(error);
  279. // });
  280.  
  281.  
  282.  
  283.  
  284. // }
  285.  
  286.  
  287.  
  288.  
  289. // const ChangeSignInForm = () => {
  290. // const container = document.getElementById('container');
  291. // container.classList.remove("right-panel-active");
  292. // }
  293.  
  294.  
  295. // const signinForm=(e)=>
  296. // {
  297.  
  298. // if(loginUser.emailSignIn && loginUser.passwordSignIn)
  299. // {
  300. // // console.log('hamaisi sign in');
  301.  
  302.  
  303. // firebase.auth().signInWithEmailAndPassword(loginUser.emailSignIn,loginUser.passwordSignIn)
  304. // .then(result=>
  305. // {
  306.  
  307. // const { displayName, emailVerified, email } = result.user;
  308.  
  309. // InsertUserInfo( { displayName, emailVerified, email });
  310.  
  311. // history.push('/home');
  312.  
  313. // window.location.reload(false);
  314.  
  315. // })
  316. // .catch(err=>
  317. // {
  318. // swal(err);
  319. // })
  320.  
  321. // }
  322.  
  323. // e.preventDefault();
  324. // }
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. return (
  336.  
  337. <div className='container'>
  338.  
  339. <a onClick={handleGoogleSignInUp}>Google</a>
  340. <br/>
  341. <a onClick={handleFbSignIn}>Facebook</a>
  342.  
  343. <br/>
  344.  
  345. <a onClick={handleSignOut}>Sign OUt</a>
  346.  
  347. </div>
  348.  
  349.  
  350.  
  351. // <div className='FormSignIN'>
  352.  
  353. // <div className="container" id="container" style={{marginTop: '115px'}}>
  354. // <div className="form-container sign-up-container">
  355.  
  356. // <form onSubmit={signupForm} className="Test" >
  357. // <h1 className="Test">Create Account</h1>
  358. // <div className="social-container">
  359. // <a className="Test" onClick={handleFbSignIn} className="social"><FaFacebook size="2rem"/></a>
  360. // <a className="Test" onClick={handleGoogleSignIn} className="social"><FcGoogle size="2rem"/></a>
  361. // </div>
  362. // <span className="Test">or use your email for registration</span>
  363. // <input className="Test" onBlur={handleBlurSignUp} name='displayName' type="text" placeholder="Name" required/>
  364. // <input className="Test" onBlur={handleBlurSignUp} name='email' type="email" placeholder="Email" required />
  365. // <input className="Test" onBlur={handleBlurSignUp} name='password' type="password" placeholder="Password" required />
  366. // <button type='submit' className="Test" >Sign Up</button>
  367. // </form>
  368.  
  369. // </div>
  370.  
  371. // <div className="form-container sign-in-container">
  372.  
  373. // <form onSubmit={signinForm} className="Test">
  374. // <h1 className="Test">Sign in</h1>
  375. // <div className="social-container">
  376. // <a className="Test" onClick={handleFbSignIn} className="social"><FaFacebook size="2rem"/></a>
  377. // <a className="Test" onClick={handleGoogleSignIn} className="social"><FcGoogle size="2rem"/></a>
  378.  
  379.  
  380. // </div>
  381. // <span className="Test">or use your account</span>
  382. // <input className="Test" onBlur={handleBlurSignIn} name='emailSignIn' type="email" placeholder="Email" required />
  383. // <input className="Test" onBlur={handleBlurSignIn} name='passwordSignIn' type="password" placeholder="Password" required/>
  384. // <a className="Test" >Forgot your password?</a>
  385. // <button type='submit' className="Test" >Sign In</button>
  386. // </form>
  387. // </div>
  388.  
  389.  
  390. // <div className="overlay-container">
  391. // <div className="overlay">
  392. // <div className="overlay-panel overlay-left">
  393. // <span style={{ 'fontFamily': 'cursive', 'fontSize': '3rem'}}><AiFillTag style={{color: 'orange'}}/><b className="logg">D</b>esh<b className="logg">M</b>art</span>
  394. // <p className="Test">Welcome back! To keep connected with us please login with your personal info</p>
  395. // <button className="ghost Test" id="signIn" onClick={ChangeSignInForm}>Sign In</button>
  396. // </div>
  397. // <div className="overlay-panel overlay-right">
  398. // <span style={{ 'fontFamily': 'cursive', 'fontSize': '3rem'}}><AiFillTag style={{color: 'orange'}}/><b className="logg">D</b>esh<b className="logg">M</b>art</span>
  399. // <p className="Test">Hello! Enter your personal details and start journey with us</p>
  400. // <button className="ghost Test" id="signUp" onClick={ChangeSignUpForm}>Sign Up</button>
  401. // </div>
  402. // </div>
  403. // </div>
  404. // </div>
  405. // </div>
  406. );
  407.  
  408. };
  409.  
  410. export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement