Skip to content

Commit

Permalink
Reduce calls to refresh user+channels+... on auth change
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Apr 21, 2024
1 parent eec8287 commit a5c4ddc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/r4-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,19 @@ export default class R4App extends LitElement {

this.listeners = new DatabaseListeners(this)
this.listeners.addEventListener('auth', async ({detail}) => {
this.user = detail.user
this.refreshUserData()
this.refreshUserAccount()
const sameUser = (this.user && this.user.id) === (detail.user && detail.user.id)
if (
detail.eventType === 'INITIAL_SESSION' ||
detail.eventType === 'SIGNED_IN' && !sameUser ||
detail.eventType === 'SIGNED_OUT'
) {
this.user = detail.user
this.refreshUserData()
this.refreshUserAccount()
} else {
// same user, no need to update
}

if (detail === 'PASSWORD_RECOVERY') {
this.passwordRecovery()
}
Expand Down

0 comments on commit a5c4ddc

Please sign in to comment.