Skip to content

Commit

Permalink
google oauth signin and token saving
Browse files Browse the repository at this point in the history
  • Loading branch information
SummySumanth committed Jan 22, 2019
1 parent 61908fb commit 29620b3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
1 change: 0 additions & 1 deletion passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ passport.use('googleToken',new googlePlusTokenStrategy({
clientID : OAuth.google.clientID,
clientSecret : OAuth.google.clientSecret
}, async (accessToken, refreshToken, profile, done)=>{
console.log('reached goooooogle');
try{
const existingUser = await User.findOne({"google.id": profile.id});
if(existingUser){
Expand Down
5 changes: 2 additions & 3 deletions routes/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ module.exports = {

},
googleOAuth : async(req, res, next)=>{
console.log('reached google o auth ');
const token = signToken(req.user, JWT_SECRET);
res.status(200).json({ token });
res.status(200).json({ token, redirect: '/home'});
},
facebookOAuth : async(req, res, next)=>{
const token = signToken(req.user, JWT_SECRET);
res.status(200).json( {token} );
res.status(200).json( {token, redirect: '/home'} );
},
signinUser: async(req, res, next) =>{
const token = signToken(req.user, JWT_SECRET);
Expand Down
11 changes: 9 additions & 2 deletions view/js/actions/auth/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {signin} from '../../services/signin/signin';

import auth from '../../services/auth/auth';
import history from '../../routes/history';
const AuthActionTypes = {
TOKEN_RECEIVED : 'TOKEN_RECEIVED',
INVALID_USER : 'INVALID_USER',
Expand All @@ -18,7 +19,13 @@ const AuthActions = {
invalidUser: (token) => ({type: AuthActionTypes.INVALID_USER, payload: token}),

googleOAuth: (data) => (dispatch) =>{
console.log('action received access token', data);
let payload = {
access_token : data
}
auth.googleSignin(payload).then(response=>{
dispatch(AuthActions.tokenReceived(response.data.token));
history.push(response.data.redirect);
})
},

tokenValidity: () =>{
Expand Down
7 changes: 3 additions & 4 deletions view/js/components/landingPage/signinContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ class Signin extends Component{
if(errObj){
return(
<div>
INVALID USERNAME OR PASSWORD changed
INVALID USERNAME OR PASSWORD
</div>
);
}

}

responseGoogle(response){
console.loh('reached response');
console.log('google response : ', response);
this.props.dispatch(AuthActions.googleOAuth(response.accessToken));
}
Expand All @@ -55,8 +54,8 @@ class Signin extends Component{
render={renderProps => (
<img class='lnf-LPcard-content-body-signin-social-logo' src='/assets/images/google.png' onClick={renderProps.onClick} />
)}
onSuccess={()=>this.responseGoogle}
onFailure={()=>this.responseGoogle}
onSuccess={(data)=>this.responseGoogle(data)}
onFailure={(data)=>this.responseGoogle(data)}
/>
<FacebookLogin
appId="273464073501603"
Expand Down
23 changes: 19 additions & 4 deletions view/js/services/auth/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// import {raiseStatus} from '../../scripts/https';
import {raiseStatus} from '../../scripts/https';
import axios from 'axios';
import axiosConfig from '../../config/axiosServices';

// export {

// }
const auth = {
googleSignin : (payload) => axios
.post('/api/oauth/google', payload)
.then(raiseStatus)
.catch(err=>{
console.log('error was found at service,', err);
}),
facebookSignin : (payload) => axios
.post('/api/signin', payload)
.then(raiseStatus)
.catch(err=>{
console.log('error was found at service,', err);
}),
}

export default auth;
2 changes: 1 addition & 1 deletion view/js/services/signin/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import axiosConfig from '../../config/axiosServices';

const signin = (payload) => axios
.post('/api/signin', payload, axiosConfig)
.post('/api/signin', payload)
.then(raiseStatus)
.catch(err=>{
console.log('error was found at service,', err);
Expand Down
2 changes: 1 addition & 1 deletion view/js/services/signup/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import axiosConfig from '../../config/axiosServices';

const signup = (payload) => axios
.post('/api/signup', payload ,axiosConfig)
.post('/api/signup', payload)
.then(raiseStatus)
.catch(err=>{
console.log('error was found at service,', err);
Expand Down

0 comments on commit 29620b3

Please sign in to comment.