Skip to content

Commit 9154033

Browse files
committed
fix
1 parent 5b4de3b commit 9154033

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/background.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2525
message.info.windowWidth
2626
);
2727
} else if (message.action === "cachePassphrase") {
28-
document.cookie = "passphrase=" + message.value;
28+
document.cookie = `passphrase="${message.value}${getCookieExpiry()}"`;
2929
cachedPassphrase = message.value;
3030
clearTimeout(autolockTimeout);
3131
setAutolock();
@@ -285,12 +285,12 @@ function getBackupToken(service: string) {
285285
xhr.open(
286286
"POST",
287287
"https://www.googleapis.com/oauth2/v4/token?client_id=" +
288-
getCredentials().drive.client_id +
289-
"&client_secret=" +
290-
getCredentials().drive.client_secret +
291-
"&code=" +
292-
value +
293-
"&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code"
288+
getCredentials().drive.client_id +
289+
"&client_secret=" +
290+
getCredentials().drive.client_secret +
291+
"&code=" +
292+
value +
293+
"&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code"
294294
);
295295
xhr.setRequestHeader("Accept", "application/json");
296296
xhr.setRequestHeader(
@@ -407,13 +407,25 @@ chrome.commands.onCommand.addListener(async (command: string) => {
407407

408408
function setAutolock() {
409409
if (Number(localStorage.autolock) > 0) {
410+
document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry()}"`;
410411
autolockTimeout = setTimeout(() => {
411-
document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"';
412412
cachedPassphrase = "";
413413
}, Number(localStorage.autolock) * 60000);
414414
}
415415
}
416416

417+
function getCookieExpiry() {
418+
if (localStorage.autolock && Number(localStorage.autolock) > 0) {
419+
const offset = Number(localStorage.autolock) * 60000;
420+
const now = new Date().getTime();
421+
const autolockExpiry = new Date(now + offset).toUTCString();
422+
423+
return `;expires=${autolockExpiry}`;
424+
} else {
425+
return "";
426+
}
427+
}
428+
417429
function getCachedPassphrase() {
418430
if (cachedPassphrase) {
419431
return cachedPassphrase;

0 commit comments

Comments
 (0)