Force refreshing token when changing AI chat permissions (fixes #766) (#837)

This commit is contained in:
David Straub
2025-11-21 12:02:03 +01:00
committed by GitHub
parent 760da4918f
commit 5b5a8e875a
3 changed files with 6 additions and 6 deletions

View File

@@ -529,7 +529,7 @@ export class GrampsJs extends LitElement {
this._handleVisibilityChange()
)
window.addEventListener('online', () => this._handleOnline())
window.addEventListener('token:refresh', () => this._handleRefresh())
window.addEventListener('token:refresh', () => this._handleRefresh(true))
if (window.location.pathname.includes('/oidc/complete')) {
return
@@ -822,8 +822,8 @@ export class GrampsJs extends LitElement {
}
// eslint-disable-next-line class-methods-use-this
async _handleRefresh() {
await this.appState.refreshTokenIfNeeded()
async _handleRefresh(force = false) {
await this.appState.refreshTokenIfNeeded(force)
this.setPermissions()
}

View File

@@ -678,8 +678,8 @@ export class Auth {
return localStorage.getItem('refresh_token')
}
async getValidAccessToken() {
if (this._shouldRefresh()) {
async getValidAccessToken(force = false) {
if (force || this._shouldRefresh()) {
if (this._refreshingTokens) {
// If already refreshing, wait for that to finish
await this._refreshingTokens

View File

@@ -41,7 +41,7 @@ export function getInitialAppState() {
apiPutPostDeleteNew(auth, 'PUT', endpoint, payload, options),
apiDelete: (endpoint, options = {}) =>
apiPutPostDeleteNew(auth, 'DELETE', endpoint, {}, options),
refreshTokenIfNeeded: () => auth.getValidAccessToken(),
refreshTokenIfNeeded: (force = false) => auth.getValidAccessToken(force),
signout: () => auth.signout(),
updateSettings: (settings = {}, tree = false) =>
updateSettings(settings, tree),