Skip to content

Commit

Permalink
fix: psd crack blocking localstorage, making it silently fail so we u…
Browse files Browse the repository at this point in the history
…se inmemory storage as backup
  • Loading branch information
uzenith360 committed Mar 18, 2024
1 parent 73275f7 commit c1a7b23
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions projects/ngx-jwt-auth/src/lib/jwt-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,33 @@ export class JwtAuthService {
private readonly setItem: (key: string, value: string) => void;
private readonly removeItem: (key: string) => void;

constructor(@Inject(EnvironmentConfigService) private config: EnvironmentConfig,) {
constructor(@Inject(EnvironmentConfigService) private config: EnvironmentConfig) {
this.storeId = config.tokenStoreId;

// handle: Failed to read the 'localStorage' property from 'Window': Access is denied for this document
if (this.isLocalStorageAvailable()) {
this.getItem = (key: string) => localStorage.getItem(key);
this.setItem = (key: string, value: string) => localStorage.setItem(key, value);
this.removeItem = (key: string) => localStorage.removeItem(key);
// even if local storage is available,
// still use inMemory cache cos of the Photoshop CRACK that makes the isLocalStorageAvailable look successfull
// but nothing gets saved to browser storage and nothing can be returned
const inMemory: InMemoryCache<string> = new InMemoryCache();

this.getItem = (key: string) => localStorage.getItem(key) ?? inMemory.get(key) ?? null;

this.setItem = (key: string, value: string) => {
try {
localStorage.setItem(key, value)
} catch (e) {
console.error(e);
}

inMemory.set(key, value);
};

this.removeItem = (key: string) => {
localStorage.removeItem(key);

inMemory.del(key);
}
} else {
const inMemory: InMemoryCache<string> = new InMemoryCache();

Expand Down

0 comments on commit c1a7b23

Please sign in to comment.