mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-22 06:01:45 +00:00
改善:立ち上げたらUserの情報(PlanetのSnippetsなどを含めた)を検証して、データを全部リロードする
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user