Skip to content

Commit

Permalink
feat: implement login / logout through GitHub
Browse files Browse the repository at this point in the history
this fixes #89
  • Loading branch information
marianzburlea committed Jul 24, 2019
1 parent 49e753a commit f602125
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/component/data/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ const firebaseConfig = {

firebase.initializeApp(firebaseConfig)
export const db = firebase.firestore()
export const auth = firebase.auth();
export const GitHubProvider = new firebase.auth.GithubAuthProvider()
26 changes: 24 additions & 2 deletions src/component/top-menu/top-menu.component.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
import React from 'react'
import React, { useState } from 'react'
import { StyledTopMenu, StyledLink, StyledButton } from './top-menu.style'
import { WebInfoState } from '../web-info/web-info.context';
import { auth, GitHubProvider } from '../data/firebase';

const TopMenu = () => {
const { toggleChat, updateToggleChat } = WebInfoState()
const [ loggedIn, setLoggedIn ] = useState(false)

const handleToggleChat = () => {
updateToggleChat({ type: 'TOGGLE_CHAT' });
}

const handleLogInAndOut = () => {
if (loggedIn) {
auth.signOut();
}
else {
auth
.signInWithPopup(GitHubProvider)
.then(user => {
console.log(user)
})
.catch(error => {
console.error(error)
})
}
}

const getLogInOutLabel = () => loggedIn ? 'Ba Bye' : 'Let me in!'

return (
<StyledTopMenu>
<StyledLink to="/">Home</StyledLink>
<StyledLink to="/dashboard">Dashboard</StyledLink>
<button>Log in</button>
<button onClick={handleLogInAndOut}>
{getLogInOutLabel()}
</button>
<StyledButton onClick={handleToggleChat}>{
toggleChat ? 'Invizi Chat' : 'Gimme chat now!'
}</StyledButton>
Expand Down

0 comments on commit f602125

Please sign in to comment.