Skip to content
Merged
1 change: 1 addition & 0 deletions packages/manager/src/OAuth/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
const codeVerifier = storage.authentication.codeVerifier.get();

if (!codeVerifier) {
alert('No code codeVerifier found in local storage when running OAuth callback.');

Check warning on line 209 in packages/manager/src/OAuth/oauth.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Replace `'No·code·codeVerifier·found·in·local·storage·when·running·OAuth·callback.'` with `⏎······'No·code·codeVerifier·found·in·local·storage·when·running·OAuth·callback.'⏎····` Raw Output: {"ruleId":"prettier/prettier","severity":1,"message":"Replace `'No·code·codeVerifier·found·in·local·storage·when·running·OAuth·callback.'` with `⏎······'No·code·codeVerifier·found·in·local·storage·when·running·OAuth·callback.'⏎····`","line":209,"column":11,"nodeType":null,"messageId":"replace","endLine":209,"endColumn":85,"fix":{"range":[6409,6483],"text":"
Comment thread
abailly-akamai marked this conversation as resolved.
Outdated
throw new AuthenticationError(
'No code codeVerifier found in local storage when running OAuth callback.'
);
Expand Down
33 changes: 27 additions & 6 deletions packages/manager/src/utilities/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { SupportTicketFormFields } from 'src/features/Support/SupportTickets/SupportTicketDialog';

const localStorageCache: Record<string, any> = {};
const sessionStorageCache: Record<string, any> = {};

Check warning on line 8 in packages/manager/src/utilities/storage.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Unexpected any. Specify a different type. Raw Output: {"ruleId":"@typescript-eslint/no-explicit-any","severity":1,"message":"Unexpected any. Specify a different type.","line":8,"column":43,"nodeType":"TSAnyKeyword","messageId":"unexpectedAny","endLine":8,"endColumn":46,"suggestions":[{"messageId":"suggestUnknown","fix":{"range":[380,383],"text":"unknown"},"desc":"Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct."},{"messageId":"suggestNever","fix":{"range":[380,383],"text":"never"},"desc":"Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of."}]}

export const getStorage = (key: string, fallback?: any) => {
if (localStorageCache[key]) {
Expand Down Expand Up @@ -48,6 +49,26 @@
window.localStorage.removeItem(key);
};


Check warning on line 52 in packages/manager/src/utilities/storage.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Delete `⏎` Raw Output: {"ruleId":"prettier/prettier","severity":1,"message":"Delete `⏎`","line":52,"column":1,"nodeType":null,"messageId":"delete","endLine":53,"endColumn":1,"fix":{"range":[1548,1549],"text":""}}
export const getSessionStorage = (key: string): string | null => {

Check failure on line 53 in packages/manager/src/utilities/storage.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Expected "null" to come before "string". Raw Output: {"ruleId":"perfectionist/sort-union-types","severity":2,"message":"Expected \"null\" to come before \"string\".","line":53,"column":58,"nodeType":"TSNullKeyword","messageId":"unexpectedUnionTypesOrder","endLine":53,"endColumn":62,"fix":{"range":[1597,1610],"text":"null | string"}}

Check failure on line 53 in packages/manager/src/utilities/storage.ts

View workflow job for this annotation

GitHub Actions / lint (linode-manager)

Expected "null" to come before "string"
if (key in sessionStorageCache) {
return sessionStorageCache[key];
}
const item = window.sessionStorage.getItem(key);
sessionStorageCache[key] = item;
return item;
};

export const setSessionStorage = (key: string, value: string) => {
sessionStorageCache[key] = value;
window.sessionStorage.setItem(key, value);
};

export const clearSessionStorage = (key: string) => {
delete sessionStorageCache[key];
window.sessionStorage.removeItem(key);
};

const PAGE_SIZE = 'PAGE_SIZE';
const INFINITE_PAGE_SIZE = 'INFINITE_PAGE_SIZE';
const TOKEN = 'authentication/token';
Expand Down Expand Up @@ -150,19 +171,19 @@
export const storage: Storage = {
authentication: {
codeVerifier: {
get: () => getStorage(CODE_VERIFIER),
set: (v) => setStorage(CODE_VERIFIER, v),
clear: () => clearStorage(CODE_VERIFIER),
get: () => getSessionStorage(CODE_VERIFIER),
set: (v) => setSessionStorage(CODE_VERIFIER, v),
clear: () => clearSessionStorage(CODE_VERIFIER),
},
expire: {
get: () => getStorage(EXPIRE),
set: (v) => setStorage(EXPIRE, v),
clear: () => clearStorage(EXPIRE),
},
nonce: {
get: () => getStorage(NONCE),
set: (v) => setStorage(NONCE, v),
clear: () => clearStorage(NONCE),
get: () => getSessionStorage(NONCE),
set: (v) => setSessionStorage(NONCE, v),
clear: () => clearSessionStorage(NONCE),
},
scopes: {
get: () => getStorage(SCOPES),
Expand Down
Loading