Skip to content

Commit bef5674

Browse files
ruchevitsmrin9
authored andcommitted
recover persisted api keys on all pages
1 parent d0b4b7c commit bef5674

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/templates/main-body-template.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import focusedEndpointTemplate from '~/templates/focused-endpoint-template';
66
import overviewTemplate from '~/templates/overview-template';
77
import endpointTemplate from '~/templates/endpoint-template';
88
import serverTemplate from '~/templates/server-template';
9-
import securitySchemeTemplate from '~/templates/security-scheme-template';
9+
import securitySchemeTemplate, { recoverPersistedApiKeys } from '~/templates/security-scheme-template';
1010
import headerTemplate from '~/templates/header-template';
1111
import navbarTemplate from '~/templates/navbar-template';
1212
import advancedSearchTemplate from '~/templates/advance-search-template';
@@ -17,6 +17,9 @@ export default function mainBodyTemplate(isMini = false, showExpandCollapse = tr
1717
if (!this.resolvedSpec) {
1818
return '';
1919
}
20+
if (this.persistAuth === 'true') {
21+
recoverPersistedApiKeys.call(this);
22+
}
2023
const newTheme = {
2124
bg1: isValidHexColor(this.bgColor) ? this.bgColor : '',
2225
fg1: isValidHexColor(this.textColor) ? this.textColor : '',

src/templates/security-scheme-template.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ function setPersistedApiKeys(obj) {
4848
localStorage.setItem(localStorageKey, JSON.stringify(obj));
4949
}
5050

51+
export function recoverPersistedApiKeys() {
52+
const rapidocLs = getPersistedApiKeys.call(this);
53+
Object.values(rapidocLs).forEach((p) => {
54+
applyApiKey.call(this, p.securitySchemeId, p.username, p.password, p.value);
55+
});
56+
}
57+
5158
function onApiKeyChange(securitySchemeId) {
5259
let apiKeyValue = '';
5360
const securityObj = this.resolvedSpec.securitySchemes.find((v) => (v.securitySchemeId === securitySchemeId));
@@ -371,12 +378,6 @@ function removeApiKey(securitySchemeId) {
371378

372379
export default function securitySchemeTemplate() {
373380
if (!this.resolvedSpec) { return ''; }
374-
if (this.persistAuth === 'true') {
375-
const rapidocLs = getPersistedApiKeys.call(this);
376-
Object.values(rapidocLs).forEach((p) => {
377-
applyApiKey.call(this, p.securitySchemeId, p.username, p.password, p.value);
378-
});
379-
}
380381
const providedApiKeys = this.resolvedSpec.securitySchemes?.filter((v) => (v.finalKeyValue));
381382
if (!providedApiKeys) {
382383
return;

0 commit comments

Comments
 (0)