fix: cache with duplicated data

This commit is contained in:
Divlo
2022-08-30 21:30:06 +02:00
parent 3d185bf044
commit a068d31d14
22 changed files with 98 additions and 95 deletions

View File

@ -16,7 +16,7 @@ export class Authentication {
constructor(tokens: Tokens, disableSocketIO: boolean = false) {
this.tokens = tokens
this.accessTokenAge = Date.now()
if (disableSocketIO || typeof window === 'undefined') {
if (typeof window === 'undefined' || disableSocketIO) {
this.socket = undefined
} else {
this.socket = io(API_URL, {

View File

@ -25,8 +25,7 @@ export const AuthenticationProvider: React.FC<
const [user, setUser] = useState<UserCurrent>(props.authentication.user)
const authentication = useMemo(() => {
const disableSocketIO = typeof window === 'undefined'
return new Authentication(props.authentication.tokens, disableSocketIO)
return new Authentication(props.authentication.tokens)
// eslint-disable-next-line react-hooks/exhaustive-deps -- We only want to run this memo once
}, [])

View File

@ -54,10 +54,13 @@ export const authenticationFromServerSide = (
}
}
} else {
let data = {}
let data: any = {}
if (fetchData != null) {
data = await fetchData(context, api)
}
if (data.notFound != null) {
return data
}
return { props: data }
}
} else {
@ -71,7 +74,7 @@ export const authenticationFromServerSide = (
} else {
try {
let data: any = {}
const authentication = new Authentication(tokens, true)
const authentication = new Authentication(tokens)
const { data: currentUser } = await authentication.api.get<
unknown,
AxiosResponse<UserCurrent>
@ -79,7 +82,7 @@ export const authenticationFromServerSide = (
if (fetchData != null) {
data = await fetchData(context, authentication.api)
}
if (data.redirect != null) {
if (data.notFound != null) {
return data
}
return {
@ -87,10 +90,7 @@ export const authenticationFromServerSide = (
}
} catch {
return {
redirect: {
destination: '/404',
permanent: false
}
notFound: true
}
}
}