fix: cache with outdated data
This commit is contained in:
parent
66f3e0475f
commit
6cfee0f6a3
1
.gitignore
vendored
1
.gitignore
vendored
@ -49,3 +49,4 @@ npm-debug.log*
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.lighthouseci
|
.lighthouseci
|
||||||
.vercel
|
.vercel
|
||||||
|
*.hbs
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
.next
|
|
||||||
.lighthouseci
|
|
||||||
coverage
|
|
||||||
node_modules
|
|
||||||
**/workbox-*.js
|
|
||||||
**/sw.js
|
|
||||||
*.hbs
|
|
@ -20,7 +20,7 @@
|
|||||||
"lint:editorconfig": "editorconfig-checker",
|
"lint:editorconfig": "editorconfig-checker",
|
||||||
"lint:markdown": "markdownlint-cli2",
|
"lint:markdown": "markdownlint-cli2",
|
||||||
"lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"",
|
"lint:typescript": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"",
|
||||||
"lint:prettier": "prettier \".\" --check",
|
"lint:prettier": "prettier \".\" --check --ignore-path \".gitignore\"",
|
||||||
"lint:staged": "lint-staged",
|
"lint:staged": "lint-staged",
|
||||||
"test:unit": "cypress run --component",
|
"test:unit": "cypress run --component",
|
||||||
"test:html-w3c-validator": "start-server-and-test \"start\" \"http://localhost:3000\" \"html-w3c-validator\"",
|
"test:html-w3c-validator": "start-server-and-test \"start\" \"http://localhost:3000\" \"html-w3c-validator\"",
|
||||||
|
@ -5,6 +5,7 @@ import { API_URL } from '../api'
|
|||||||
import { cookies } from '../cookies'
|
import { cookies } from '../cookies'
|
||||||
import { Tokens } from '.'
|
import { Tokens } from '.'
|
||||||
import { fetchRefreshToken } from './authenticationFromServerSide'
|
import { fetchRefreshToken } from './authenticationFromServerSide'
|
||||||
|
import { clearCache } from '../cache'
|
||||||
|
|
||||||
export class Authentication {
|
export class Authentication {
|
||||||
public tokens: Tokens
|
public tokens: Tokens
|
||||||
@ -99,7 +100,7 @@ export class Authentication {
|
|||||||
|
|
||||||
public signout(): void {
|
public signout(): void {
|
||||||
cookies.remove('refreshToken')
|
cookies.remove('refreshToken')
|
||||||
window.localStorage.clear()
|
clearCache()
|
||||||
window.location.href = '/authentication/signin'
|
window.location.href = '/authentication/signin'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +121,7 @@ export class Authentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public signin(): void {
|
public signin(): void {
|
||||||
|
clearCache()
|
||||||
cookies.set('refreshToken', this.tokens.refreshToken)
|
cookies.set('refreshToken', this.tokens.refreshToken)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ export type CacheKey =
|
|||||||
export const getPaginationCache = <T extends PaginationItem>(
|
export const getPaginationCache = <T extends PaginationItem>(
|
||||||
key: CacheKey
|
key: CacheKey
|
||||||
): T[] => {
|
): T[] => {
|
||||||
const cache = localStorage.getItem(key)
|
const cache = sessionStorage.getItem(key)
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(cache)
|
const data = JSON.parse(cache)
|
||||||
@ -30,5 +30,9 @@ export const savePaginationCache = <T extends PaginationItem>(
|
|||||||
key: CacheKey,
|
key: CacheKey,
|
||||||
data: T[]
|
data: T[]
|
||||||
): void => {
|
): void => {
|
||||||
localStorage.setItem(key, JSON.stringify(data))
|
sessionStorage.setItem(key, JSON.stringify(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearCache = (): void => {
|
||||||
|
sessionStorage.clear()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user