Skip to content

Commit

Permalink
added oauths
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasbindar Singh authored and Jasbindar Singh committed May 20, 2020
1 parent 63a0dee commit 4026521
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 73 deletions.
31 changes: 28 additions & 3 deletions src/Login/FacebookLogin.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import React from 'react';
import React, {useState} from 'react';
import { Icon } from '@iconify/react';
import bxlFacebookSquare from '@iconify/icons-bx/bxl-facebook-square';
import firebase, { auth } from '../configs/firebase'
import Loader from '../Loader/Loader';

function FacebookLogin() {

const [isLoading, setIsLoading] = useState(false)

async function handleLogin(){
setIsLoading(true)

var provider = new firebase.auth.FacebookAuthProvider();

await auth.signInWithRedirect(provider).catch(err => alert(err.message));

await auth.getRedirectResult().then(function(result) {
// var user = result.user;
setIsLoading(false)
}).catch(function(error) {
setIsLoading(false)
alert(error.message)
});
}

return (
<div className="w-full px-8 py-2 rounded text-white flex my-8 cursor-pointer" style={{backgroundColor: "#3b5998"}}>
<div className="mr-4"><Icon icon={bxlFacebookSquare} style={{color: '#fff', fontSize: '25px'}} /></div>
<div className="w-full px-8 py-2 rounded text-white flex my-8 cursor-pointer" style={{backgroundColor: "#3b5998"}} onClick={handleLogin}>
<div className="mr-4">
{
isLoading ? <Loader size="25"/> : <Icon icon={bxlFacebookSquare} style={{color: '#fff', fontSize: '25px'}} />
}
</div>
<p>Facebook</p>
</div>
)
Expand Down
31 changes: 28 additions & 3 deletions src/Login/GithubLogin.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import React from 'react';
import React, {useState} from 'react';
import { Icon } from '@iconify/react';
import bxlGithub from '@iconify/icons-bx/bxl-github';
import firebase, { auth } from '../configs/firebase'
import Loader from '../Loader/Loader';

function GithubLogin() {

const [isLoading, setIsLoading] = useState(false)

async function handleLogin(){
setIsLoading(true)

var provider = new firebase.auth.GithubAuthProvider();

await auth.signInWithRedirect(provider).catch(err => alert(err.message));

await auth.getRedirectResult().then(function(result) {
// var user = result.user;
setIsLoading(false)
}).catch(function(error) {
setIsLoading(false)
alert(error.message)
});
}

return (
<div className="w-full px-8 py-2 rounded text-white flex my-8 cursor-pointer" style={{backgroundColor: "#211F1F"}}>
<div className="mr-4"><Icon icon={bxlGithub} style={{color: '#fff', fontSize: '25px'}} /></div>
<div className="w-full px-8 py-2 rounded text-white flex my-8 cursor-pointer" style={{backgroundColor: "#211F1F"}} onClick={handleLogin}>
<div className="mr-4">
{
isLoading ? <Loader size="25"/> : <Icon icon={bxlGithub} style={{color: '#fff', fontSize: '25px'}} />
}
</div>
<p>Github</p>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/Login/GoogleLogin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import bxlGoogle from '@iconify/icons-bx/bxl-google';
import firebase, { auth } from '../configs/firebase'
import Loader from '../Loader/Loader';

function GoogleLogin(props) {
function GoogleLogin() {

const [isLoading, setIsLoading] = useState(false)

Expand Down
10 changes: 4 additions & 6 deletions src/Login/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {useContext} from 'react'
import AppleLogin from './AppleLogin'
// import AppleLogin from './AppleLogin'
import GithubLogin from './GithubLogin'
import GoogleLogin from './GoogleLogin'
import FacebookLogin from './FacebookLogin'
import TwitterLogin from './TwitterLogin'
// import TwitterLogin from './TwitterLogin'
import AnonymousLogin from './AnonymousLogin'
import { AuthContext } from '../App'
import { Redirect } from 'react-router-dom'
Expand All @@ -22,12 +22,10 @@ function Login() {
<div className="bg-cgray-light px-16 py-8 login">
<p className="text-white text-4xl mb-2">Login</p>
<div className="h-1 bg-white"></div>
<div className="my-12 font-medium">
<AppleLogin/>
<GithubLogin/>
<div className="my-12 font-medium">
<GoogleLogin/>
<FacebookLogin/>
<TwitterLogin/>
<GithubLogin/>
<AnonymousLogin/>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/Modal/ModalAdd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function ModalAdd({isOpen, toggle}) {
setIsLoading(false)
toggle()
addNote(note)
setNoteTitle("")
})
.catch(err => err.message)
}
Expand All @@ -86,6 +87,7 @@ function ModalAdd({isOpen, toggle}) {
placeholder={isAnonymous ? "Login to add more notes." : "Enter your note title..."}
onChange={handleChange}
disabled={isAnonymous}
value={noteTitle}
></textarea>
{
error.hasError ? <p className="mx-4 text-sm tracking-wide text-red-600">{error.message}</p> : null
Expand Down
Loading

0 comments on commit 4026521

Please sign in to comment.