fix: prevent auth logout by sending refresh request without expired access token header
This commit is contained in:
@@ -285,16 +285,24 @@ class DirectusService {
|
|||||||
if (!this.refreshToken) return false
|
if (!this.refreshToken) return false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.post('/auth/refresh', {
|
const response = await fetch(`${this.baseUrl}/auth/refresh`, {
|
||||||
refresh_token: this.refreshToken,
|
method: 'POST',
|
||||||
mode: 'json'
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
refresh_token: this.refreshToken,
|
||||||
|
mode: 'json'
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!response.ok) throw new Error('Refresh failed')
|
||||||
|
|
||||||
|
const result = await response.json()
|
||||||
|
|
||||||
if (response.data) {
|
if (result.data) {
|
||||||
this.saveTokens(
|
this.saveTokens(
|
||||||
response.data.access_token,
|
result.data.access_token,
|
||||||
response.data.refresh_token,
|
result.data.refresh_token,
|
||||||
response.data.expires
|
result.data.expires
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ class NotificationsService {
|
|||||||
async refresh() {
|
async refresh() {
|
||||||
if (!this.userHash) return
|
if (!this.userHash) return
|
||||||
|
|
||||||
|
if (!auth.isLoggedIn()) {
|
||||||
|
this.destroy()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [count, notifications] = await Promise.all([
|
const [count, notifications] = await Promise.all([
|
||||||
directus.getUnreadCount(this.userHash),
|
directus.getUnreadCount(this.userHash),
|
||||||
@@ -42,7 +47,9 @@ class NotificationsService {
|
|||||||
this.notifications = notifications
|
this.notifications = notifications
|
||||||
this.notify()
|
this.notify()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to fetch notifications:', e)
|
if (e.status === 401 || e.status === 403) {
|
||||||
|
this.stopPolling()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user