mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
check if token is expired only if expires_in prop is present, clear response and clear timeline are 2 different things, clear redux state after clearing oauth2 credentials cache
This commit is contained in:
@@ -1297,12 +1297,13 @@ export const refreshOauth2Credentials = (payload) => async (dispatch, getState)
|
||||
return new Promise((resolve, reject) => {
|
||||
window.ipcRenderer
|
||||
.invoke('renderer:refresh-oauth2-credentials', { request, collection })
|
||||
.then(({ credentials, url, collectionUid, debugInfo }) => {
|
||||
.then(({ credentials, url, collectionUid, debugInfo, credentialsId }) => {
|
||||
dispatch(
|
||||
collectionAddOauth2CredentialsByUrl({
|
||||
credentials,
|
||||
url,
|
||||
collectionUid,
|
||||
credentialsId,
|
||||
debugInfo,
|
||||
folderUid: folderUid || null,
|
||||
itemId: !folderUid ? itemId : null
|
||||
@@ -1320,8 +1321,12 @@ export const clearOauth2Cache = (payload) => async (dispatch, getState) => {
|
||||
window.ipcRenderer
|
||||
.invoke('clear-oauth2-cache', collectionUid, url, credentialsId)
|
||||
.then(() => {
|
||||
// We do not dispatch any action to modify the Redux store,
|
||||
// since we are only clearing the session on the main process side.
|
||||
dispatch(
|
||||
collectionClearOauth2CredentialsByUrl({
|
||||
url,
|
||||
collectionUid,
|
||||
})
|
||||
);
|
||||
resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
|
||||
@@ -324,6 +324,23 @@ export const collectionsSlice = createSlice({
|
||||
}
|
||||
}
|
||||
},
|
||||
clearTimeline: (state, action) => {
|
||||
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
||||
|
||||
if (collection) {
|
||||
collection.timeline = [];
|
||||
}
|
||||
},
|
||||
clearRequestTimeline: (state, action) => {
|
||||
const { collectionUid, itemUid } = action.payload || {};
|
||||
const collection = findCollectionByUid(state.collections, collectionUid);
|
||||
|
||||
if (collection) {
|
||||
if (itemUid) {
|
||||
collection.timeline = collection?.timeline?.filter(t => t?.itemUid !== itemUid);
|
||||
}
|
||||
}
|
||||
},
|
||||
saveRequest: (state, action) => {
|
||||
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
||||
|
||||
@@ -2119,7 +2136,19 @@ export const collectionsSlice = createSlice({
|
||||
},
|
||||
|
||||
collectionClearOauth2CredentialsByUrl: (state, action) => {
|
||||
// Since we don't want to remove tokens from oauth2Credentials or timeline,
|
||||
const { collectionUid, url, credentialsId } = action.payload;
|
||||
const collection = findCollectionByUid(state.collections, collectionUid);
|
||||
if (!collection) return;
|
||||
|
||||
if (collection.oauth2Credentials) {
|
||||
let collectionOauth2Credentials = cloneDeep(collection.oauth2Credentials);
|
||||
const filteredOauth2Credentials = filter(
|
||||
collectionOauth2Credentials,
|
||||
(creds) =>
|
||||
!(creds.url === url && creds.collectionUid === collectionUid)
|
||||
);
|
||||
collection.oauth2Credentials = filteredOauth2Credentials;
|
||||
}
|
||||
},
|
||||
|
||||
collectionGetOauth2CredentialsByUrl: (state, action) => {
|
||||
@@ -2167,6 +2196,8 @@ export const {
|
||||
requestCancelled,
|
||||
responseReceived,
|
||||
responseCleared,
|
||||
clearTimeline,
|
||||
clearRequestTimeline,
|
||||
saveRequest,
|
||||
deleteRequestDraft,
|
||||
newEphemeralHttpRequest,
|
||||
|
||||
Reference in New Issue
Block a user