You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
611 B
24 lines
611 B
import { CACHE_SCOPE_PUBLIC } from '$libs/cache';
|
|
import type { AuthClientCachePort } from '$libs/auth/contracts';
|
|
import type { ActiveCache } from '$cache';
|
|
import type { ActivePermissions } from '$permissions';
|
|
|
|
export function createAuthCacheInvalidator(input: {
|
|
readonly cache: ActiveCache;
|
|
readonly permissions: () => ActivePermissions | undefined;
|
|
}): AuthClientCachePort {
|
|
return {
|
|
async invalidate(event) {
|
|
input.permissions()?.invalidate();
|
|
await Promise.all(
|
|
event.tags.map((tag) =>
|
|
input.cache.invalidate({
|
|
tag,
|
|
scope: CACHE_SCOPE_PUBLIC
|
|
})
|
|
)
|
|
);
|
|
}
|
|
};
|
|
}
|