Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRivers committed Jan 16, 2025
1 parent 8c7dbf7 commit 0368e77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
8 changes: 5 additions & 3 deletions lib/utils/exchangeAuthCode.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { exchangeAuthCode } from ".";
import { MemoryStorage, StorageKeys } from "../sessionManager";
import { setActiveStorage, clearActiveStorage, clearInsecureStorage } from "./token";
import {
setActiveStorage,
clearActiveStorage,
clearInsecureStorage,
} from "./token";
import createFetchMock from "vitest-fetch-mock";
import { frameworkSettings } from "./exchangeAuthCode";
import * as refreshTokenTimer from "./refreshTimer";
Expand Down Expand Up @@ -412,7 +416,6 @@ describe("exchangeAuthCode", () => {
urlParams.append("state", "test");
urlParams.append("code", "test");


const result = await exchangeAuthCode({
urlParams,
domain: "test.com",
Expand Down Expand Up @@ -449,7 +452,6 @@ describe("exchangeAuthCode", () => {
redirectURL: "test.com",
});
} catch (error) {

expect((error as Error).message).toBe("Fetch failed");
}
});
Expand Down
46 changes: 23 additions & 23 deletions lib/utils/getCookie.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
export function getCookie(name: string): string | null {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.startsWith(name + '=')) {
const cookieValue = cookie.substring(name.length + 1);
const parts = cookieValue.split(';');
let hasExpiration = false;
for (let j = 0; j < parts.length; j++) {
const part = parts[j].trim();
if (part.startsWith('expires=')) {
hasExpiration = true;
const expirationDate = new Date(part.substring(8));
if (expirationDate > new Date()) {
return cookieValue || null; // Cookie is valid
} else {
return null; // Cookie is expired
}
}
}
if (!hasExpiration) {
return cookieValue || null; // Cookie has no expiration, so it's valid
}
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.startsWith(name + "=")) {
const cookieValue = cookie.substring(name.length + 1);
const parts = cookieValue.split(";");
let hasExpiration = false;
for (let j = 0; j < parts.length; j++) {
const part = parts[j].trim();
if (part.startsWith("expires=")) {
hasExpiration = true;
const expirationDate = new Date(part.substring(8));
if (expirationDate > new Date()) {
return cookieValue || null; // Cookie is valid
} else {
return null; // Cookie is expired
}
}

Check warning on line 19 in lib/utils/getCookie.ts

View check run for this annotation

Codecov / codecov/patch

lib/utils/getCookie.ts#L12-L19

Added lines #L12 - L19 were not covered by tests
}
if (!hasExpiration) {
return cookieValue || null; // Cookie has no expiration, so it's valid
}
}
return null; // Cookie not found
}
return null; // Cookie not found
}

0 comments on commit 0368e77

Please sign in to comment.