Commit 70108a88 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: clear cache on sign in

parent 8096624e
Pipeline #209450 failed with stages
in 4 minutes and 42 seconds
......@@ -15,7 +15,7 @@ export function validateCommonFormFields<
| PublicationCore
| ToolCore
| TrainingMaterialCore
| WorkflowCore
| WorkflowCore,
>(
values: Partial<T>,
errors: Partial<Record<keyof typeof values, any>>,
......@@ -40,7 +40,6 @@ export function validateCommonFormFields<
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (url != null && !isUrl(url)) {
if (errors.accessibleAt === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.accessibleAt = []
}
errors.accessibleAt[index] = 'Must be a valid URL.'
......@@ -58,7 +57,6 @@ export function validateCommonFormFields<
contributor.actor === undefined
) {
if (errors.contributors === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.contributors = []
}
errors.contributors[index] = {
......@@ -78,7 +76,6 @@ export function validateCommonFormFields<
contributor.role === undefined
) {
if (errors.contributors === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.contributors = []
}
errors.contributors[index] = {
......@@ -98,7 +95,6 @@ export function validateCommonFormFields<
(property.value !== undefined || property.concept !== undefined)
) {
if (errors.properties === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.properties = []
}
errors.properties[index] = {
......@@ -129,7 +125,6 @@ export function validateCommonFormFields<
(type === 'float' && !Number.isFinite(Number(property.value)))
) {
if (errors.properties === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.properties = []
}
errors.properties[index] = {
......@@ -152,7 +147,6 @@ export function validateCommonFormFields<
property.concept === undefined
) {
if (errors.properties === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.properties = []
}
errors.properties[index] = {
......@@ -173,7 +167,6 @@ export function validateCommonFormFields<
item.persistentId === undefined
) {
if (errors.relatedItems === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.relatedItems = []
}
errors.relatedItems[index] = { persistentId: 'Please select an item.' }
......@@ -191,7 +184,6 @@ export function validateCommonFormFields<
item.relation === undefined
) {
if (errors.relatedItems === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.relatedItems = []
}
errors.relatedItems[index] = {
......@@ -212,7 +204,6 @@ export function validateCommonFormFields<
id.identifier == null
) {
if (errors.externalIds === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.externalIds = []
}
errors.externalIds[index] = {
......@@ -233,7 +224,6 @@ export function validateCommonFormFields<
id.identifierService?.code == null
) {
if (errors.externalIds === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.externalIds = []
}
errors.externalIds[index] = {
......
......@@ -43,7 +43,12 @@ export function useAuth(): Auth {
*/
export default function AuthProvider({
children,
}: PropsWithChildren<unknown>): JSX.Element {
onSignIn,
onSignOut,
}: PropsWithChildren<{
onSignIn?: () => void
onSignOut?: () => void
}>): JSX.Element {
const [session, setSession] = useLocalStorage<Session | null>('session', null)
const auth = useMemo(() => {
......@@ -57,11 +62,13 @@ export default function AuthProvider({
accessToken: token,
expiresAt: decoded.exp,
})
onSignIn?.()
}
}
function signOut() {
setSession(null)
onSignOut?.()
}
function validateToken(token: string) {
......
......@@ -5,7 +5,6 @@ import type { NextRouter } from 'next/router'
import { useRouter } from 'next/router'
import type { PropsWithChildren, Ref } from 'react'
import { Fragment, useEffect, useState } from 'react'
import { useQueryClient } from 'react-query'
import { useGetItemCategories, useGetLoggedInUser } from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
......@@ -243,7 +242,6 @@ function ReportAnIssueButton({
function AuthButton() {
const router = useRouter()
const auth = useAuth()
const queryClient = useQueryClient()
const { data: user } = useGetLoggedInUser(
{
......@@ -278,8 +276,6 @@ function AuthButton() {
function onSignOut() {
auth.signOut()
/** clear the whole query cache to be on the safe side */
queryClient.clear()
router.replace(
getRedirectPath(getScalarQueryParameter(router.query.from)) ?? '/',
)
......
......@@ -94,7 +94,12 @@ function Providers({ children }: PropsWithChildren<unknown>) {
<SSRProvider>
<I18nProvider locale="en">
<QueryClientProvider client={queryClient}>
<AuthProvider>{children}</AuthProvider>
<AuthProvider
onSignIn={queryClient.clear}
onSignOut={queryClient.clear}
>
{children}
</AuthProvider>
</QueryClientProvider>
</I18nProvider>
</SSRProvider>
......
import BrowseLayout from '@/screens/browse/BrowseLayout.tsx'
import BrowseLayout from '@/screens/browse/BrowseLayout'
export default function BrowseActivitiesScreen(): JSX.Element {
return (
......
import BrowseLayout from '@/screens/browse/BrowseLayout.tsx'
import BrowseLayout from '@/screens/browse/BrowseLayout'
export default function BrowseKeywordsScreen(): JSX.Element {
return (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment