Last active
June 16, 2017 13:25
-
-
Save constellates/a76132ed7de74610a435 to your computer and use it in GitHub Desktop.
React OAuth 2 user store with Hello.js
This file contains hidden or 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
// dependencies ---------------------------------------------------------------------- | |
import Reflux from 'reflux'; | |
import Actions from '../actions/Actions'; | |
import request from 'superagent'; | |
import config from '../config'; | |
let UserStore = Reflux.createStore({ | |
// store setup ----------------------------------------------------------------------- | |
listenables: Actions, | |
/** | |
* Init | |
* | |
* Initializes hello.js with the google client ID when | |
* the store initializes. | |
*/ | |
init: function () { | |
hello.init({google: config.auth.google.clientID}); | |
}, | |
// Actions --------------------------------------------------------------------------- | |
/** | |
* Log In | |
* | |
* Starts the google OAuth2 sign in flow. | |
*/ | |
signIn: function () { | |
let self = this; | |
hello('google').login({scope: 'email,openid'}, function (userdata) { | |
self.data = userdata; // ??????????????????????????????????????????????????? | |
console.log('signin success'); | |
}, function () { | |
console.log('signin failure'); | |
}); | |
}, | |
/** | |
* Sign Out | |
* | |
* Signs the user out by destroying the current | |
* OAuth2 session. | |
*/ | |
signOut: function () { | |
hello('google').logout().then(function () { | |
console.log('signout success'); | |
}, function (e) { | |
console.log('signout failure'); | |
console.log(e); | |
}); | |
}, | |
/** | |
* Log Token | |
* | |
* Logs the current google access token stored in local storage. | |
*/ | |
logToken: function () { | |
console.log(JSON.parse(window.localStorage.hello).google.access_token); | |
}, | |
/** | |
* Get User Data | |
* | |
*/ | |
getUserData: function () { | |
return this.data; // ??????????????????????????????????????????????????? | |
} | |
}); | |
export default UserStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment