Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
signOut(uploadStatus) {
let signout = true;
if (uploadStatus === 'uploading') {
signout = confirm('You are currently uploading files. Signing out of this site will cancel the upload process. Are you sure you want to sign out?');
}
if (signout) {
hello('google').logout().then(() => {
upload.setInitialState();
this.clearAuth();
router.transitionTo('signIn');
}, () => {
// signout failure
});
}
},
async oauthLogin (ev) {
ev.preventDefault();
const id = ev.target.getAttribute('data-id');
this.provider = _converse.oauth_providers.get(id);
this.oauth_service = hello(id);
const data = {};
data[id] = this.provider.get('client_id');
hello.init(data, {
'redirect_uri': '/redirect.html'
});
await this.oauth_service.login();
this.fetchOAuthProfileDataAndLogin();
}
});
return (dispatch) => {
hello('github').logout()
.then(() => {
dispatch(receiveSignedOut());
}, console.log.bind(console));
};
}
* errors: null,
* events: payload
* }
* })
*
*/
export const reducer = createReducer({
[types.LOGGED_IN]: (state, {payload}) => {
return {
...state,
currentUser: payload.authResponse
}
}
});
const twitterAuth = hello('twitter').getAuthResponse();
const currentUser = !!twitterAuth && !twitterAuth.error && twitterAuth
/*
* The initial state for this part of the component tree
*/
export const initialState = {
loading: false,
errors: null,
currentUser: currentUser
};
.then(auth => {
hellojs(auth.network).api('/me').then(user => {
resolve({
user: {
access_token: auth.authResponse.access_token,
...user,
},
});
});
}, err => resolve({ error: err.error }));
});
isTokenValid() {
var session = hello('google').getAuthResponse();
var currentTime = (new Date()).getTime() / 1000;
return session && session.access_token && session.expires > currentTime;
},
loginWithTwitter: () => (dispatch, getState) => {
hello('twitter').login()
.then(res => {
dispatch({type: types.LOGGED_IN, payload: res});
}, err => {
dispatch({type: types.ERROR_LOGGING_IN, payload: res});
})
}
}
this.checkAuth((token) => {
this.update({token: token});
hello('google').api('/me').then((profile) => {
this.update({google: profile});
crn.verifyUser((err, res) => {
if (res.body.code === 403) {
this.signOut();
} else {
window.localStorage.scitranUser = JSON.stringify(res.body);
this.update({scitran: res.body});
}
});
}, () => {
this.setInitialState();
});
}, this.clearAuth);
} else {
signIn(options) {
let transition = options.hasOwnProperty('transition') ? options.transition : true;
this.update({loading: true});
hello('google').login({scope: 'email,openid'}, (res) => {
if (res.error) {
this.update({loading: false});
return;
}
this.update({token: res.authResponse.access_token});
hello(res.network).api('/me').then((profile) => {
crn.verifyUser((err, res) => {
if (res.body.code === 403) {
let user = {
_id: profile.email,
firstname: profile.first_name,
lastname: profile.last_name
};
crn.createUser(user, (err, res) => {
if (res.body.status === 403) {
this.clearAuth();
return (dispatch) => {
hello('github').api('me')
.then((user) => {
dispatch(receiveGithubUsername(user.name));
});
};
}