Handle redirect to entry on one time code expiration

This commit is contained in:
Daniel Nyvik 2024-04-04 13:58:54 +02:00
parent 4a4551a199
commit 2b757762cd
2 changed files with 21 additions and 16 deletions

View File

@ -191,14 +191,15 @@ ready(() => {
}
function openVaultFromQueryParam() {
const vault = getVaultParam();
const vault = getQueryParamByName('vault');
const entryId = getQueryParamByName('entryId');
if (vault) {
let fileInfo = appModel.fileInfos.getByPath(`/api/passwordbank/vaults/${vault}`);
if (!fileInfo) {
fileInfo = appModel.fileInfos.getByName(vault);
}
if (fileInfo) {
appView.views.open.showOpenFileInfo(fileInfo, true);
appView.views.open.showOpenFileInfo(fileInfo, true, entryId);
}
}
}
@ -219,16 +220,14 @@ ready(() => {
if (metaConfig && metaConfig.content && metaConfig.content[0] !== '(') {
return metaConfig.content;
}
const match = location.search.match(/[?&]config=([^&]+)/i);
if (match && match[1]) {
return match[1];
}
return getQueryParamByName('config');
}
function getVaultParam() {
const match = location.search.match(/[?&]vault=([^&]+)/i);
if (match && match[1]) {
return decodeURIComponent(match[1]);
function getQueryParamByName(name) {
const searchParams = new URLSearchParams(location.search);
if (searchParams.has(name)) {
return searchParams.get(name);
}
return null;
}
});

View File

@ -169,7 +169,7 @@ async function renamePasswordVault(path, title) {
}
}
async function getPasswordForPasswordVault(path) {
async function getPasswordForPasswordVault(path, entryId) {
const passwordVaultToGetPasswordFor = getPasswordVaultFromPath(path);
try {
const response = await passwordBankFetch(
@ -180,11 +180,17 @@ async function getPasswordForPasswordVault(path) {
);
return await response.json();
} catch (error) {
window.location = `/onetimecode?title=${encodeURIComponent(
Locale.passwordBankTitle
)}&redirectUri=${encodeURIComponent(
`/passwordbank/?vault=${passwordVaultToGetPasswordFor}`
)}`;
const oneTimeCodeUri = new URL('/onetimecode');
oneTimeCodeUri.searchParams.set('title', Locale.passwordBankTitle);
const redirectUri = new URL('/passwordbank');
redirectUri.searchParams.set('vault', passwordVaultToGetPasswordFor);
if (entryId) {
redirectUri.searchParams.set('entryId', entryId);
}
oneTimeCodeUri.searchParams.set('redirectUri', redirectUri.toString());
window.location = oneTimeCodeUri.toString();
}
}