1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-22 06:01:45 +00:00

改善:立ち上げたらUserの情報(PlanetのSnippetsなどを含めた)を検証して、データを全部リロードする

This commit is contained in:
Rokt33r
2015-07-29 02:18:44 +09:00
parent 51fb43d624
commit 714b5f7b4b
3 changed files with 39 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ var AuthStore = Reflux.createStore({
this.listenTo(AuthActions.register, this.register)
this.listenTo(AuthActions.logout, this.logout)
this.listenTo(AuthActions.updateProfile, this.updateProfile)
this.listenTo(AuthActions.refreshUser, this.refreshUser)
},
// Reflux Store
login: function (input) {
@@ -58,6 +59,30 @@ var AuthStore = Reflux.createStore({
})
}.bind(this))
},
refreshUser: function () {
request
.get(apiUrl + 'auth/user')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
})
.end(function (err, res) {
if (err) {
console.error(err)
if (res.status === 401 || res.status === 403) {
AuthActions.logout()
}
return
}
var user = res.body
localStorage.setItem('user', JSON.stringify(user))
this.trigger({
status: 'userRefreshed',
data: user
})
}.bind(this))
},
logout: function () {
localStorage.removeItem('token')
localStorage.removeItem('user')