Skip to content

Instantly share code, notes, and snippets.

@schovi
Created February 19, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schovi/c90d0450aa4ae11b5ae64c9d0ff5c0d6 to your computer and use it in GitHub Desktop.
Save schovi/c90d0450aa4ae11b5ae64c9d0ff5c0d6 to your computer and use it in GitHub Desktop.
import Auth0 from '...'
class Auth0Store {
@observable authenticating = true
@observable profile = null
constructor() {
this.profile = Auth0.currentProfile
Auth0.on('authenticated', this.authenticatedDone)
}
@action() {
this.authenticating = false
}
}
export default new Auth0Store()
// In my global store I will have
import Auth0Store from '...'
class Store {
auth = Auth0Store
}
export default new Store
// file auth0_store.js
const Auth0Store = types.model('Auth0Store', {
authenticating: true,
profile: types.maybe(types.map({...}))
}).actions(self => {
return {
authenticated() {self.authenticating = false}
}
})
// file store.js
const Store = types.model('Store', {
auth: Auth0Store
})
// file state.js
import Auth0 from '...'
const state = Store.create({
auth: Auth0.currentProfile
})
Auth0.on('authenticated', () => {
state.auth.authenticated()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment