-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store authentication details in Redux.
- Loading branch information
Showing
9 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { SIGN_IN, SIGN_OUT } from "./types"; | ||
|
||
// https://developers.google.com/identity/sign-in/web/reference#users | ||
export const registerLogin = (googleUser) => { | ||
const profile = googleUser.getBasicProfile(); | ||
return { | ||
type: SIGN_IN, | ||
payload: { | ||
userid: profile.getId(), | ||
username: profile.getName(), | ||
email: profile.getEmail() | ||
} | ||
}; | ||
}; | ||
|
||
export const registerLogout = () => { | ||
return { | ||
type: SIGN_OUT, | ||
payload: {} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SIGN_IN = "SIGN_IN"; | ||
export const SIGN_OUT = "SIGN_OUT"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
const GoogleButton = ({ color = "blue", onClick, label }) => { | ||
return ( | ||
<button className={`ui ${color} google button`} onClick={onClick}> | ||
<i className='google icon'></i> | ||
{label} | ||
</button> | ||
); | ||
}; | ||
|
||
export default GoogleButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { Provider } from "react-redux"; | ||
import { createStore } from "redux"; | ||
|
||
import App from "./components/App"; | ||
import reducers from "./reducers"; | ||
|
||
const store = createStore(reducers); | ||
|
||
ReactDOM.render(<App />, document.getElementById("root")); | ||
ReactDOM.render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider>, | ||
document.getElementById("root") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { combineReducers } from "redux"; | ||
import { SIGN_IN, SIGN_OUT } from "../actions/types"; | ||
|
||
const SIGNED_OUT_STATE = { | ||
isSignedIn: false, | ||
userid: null, | ||
username: null, | ||
email: null | ||
}; | ||
|
||
const authenticationReducer = (state = SIGNED_OUT_STATE, action) => { | ||
switch (action.type) { | ||
case SIGN_IN: | ||
return { | ||
isSignedIn: true, | ||
userid: action.payload.userid, | ||
username: action.payload.username, | ||
email: action.payload.email | ||
}; | ||
case SIGN_OUT: | ||
return SIGNED_OUT_STATE; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default combineReducers({ authDetails: authenticationReducer }); |