fix: read-after-write issues (#215)
* fix: read-after-write issues * fix: coderabbit comments * fix: clear cache on invite * fix: use primary after a read
This commit is contained in:
committed by
GitHub
parent
abacf66155
commit
f454449365
@@ -20,6 +20,7 @@ import {
|
||||
getUserAccount,
|
||||
} from '@openpanel/db';
|
||||
import { sendEmail } from '@openpanel/email';
|
||||
import { deleteCache } from '@openpanel/redis';
|
||||
import {
|
||||
zRequestResetPassword,
|
||||
zResetPassword,
|
||||
@@ -74,6 +75,7 @@ export const authRouter = createTRPCRouter({
|
||||
deleteSessionTokenCookie(ctx.setCookie);
|
||||
if (ctx.session?.session?.id) {
|
||||
await invalidateSession(ctx.session.session.id);
|
||||
await deleteCache(`validateSession:${ctx.session.session.id}`);
|
||||
}
|
||||
}),
|
||||
signInOAuth: publicProcedure
|
||||
@@ -333,6 +335,7 @@ export const authRouter = createTRPCRouter({
|
||||
const session = await validateSessionToken(token);
|
||||
|
||||
if (session.session) {
|
||||
await deleteCache(`validateSession:${session.session.id}`);
|
||||
// Re-set the cookie with updated expiration
|
||||
setSessionTokenCookie(ctx.setCookie, token, session.session.expiresAt);
|
||||
return {
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
differenceInWeeks,
|
||||
formatISO,
|
||||
} from 'date-fns';
|
||||
import { getProjectAccessCached } from '../access';
|
||||
import { getProjectAccess } from '../access';
|
||||
import { TRPCAccessError } from '../errors';
|
||||
import {
|
||||
cacheMiddleware,
|
||||
@@ -367,7 +367,7 @@ export const chartRouter = createTRPCRouter({
|
||||
.input(zChartInput)
|
||||
.query(async ({ input, ctx }) => {
|
||||
if (ctx.session.userId) {
|
||||
const access = await getProjectAccessCached({
|
||||
const access = await getProjectAccess({
|
||||
projectId: input.projectId,
|
||||
userId: ctx.session.userId,
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
} from '@openpanel/validation';
|
||||
|
||||
import { clone } from 'ramda';
|
||||
import { getProjectAccessCached } from '../access';
|
||||
import { getProjectAccess } from '../access';
|
||||
import { TRPCAccessError } from '../errors';
|
||||
import { createTRPCRouter, protectedProcedure, publicProcedure } from '../trpc';
|
||||
|
||||
@@ -266,7 +266,7 @@ export const eventRouter = createTRPCRouter({
|
||||
)
|
||||
.query(async ({ input: { projectId, cursor, limit }, ctx }) => {
|
||||
if (ctx.session.userId) {
|
||||
const access = await getProjectAccessCached({
|
||||
const access = await getProjectAccess({
|
||||
projectId,
|
||||
userId: ctx.session.userId,
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
zCreateSlackIntegration,
|
||||
zCreateWebhookIntegration,
|
||||
} from '@openpanel/validation';
|
||||
import { getOrganizationAccessCached } from '../access';
|
||||
import { getOrganizationAccess } from '../access';
|
||||
import { TRPCAccessError } from '../errors';
|
||||
import { createTRPCRouter, protectedProcedure } from '../trpc';
|
||||
|
||||
@@ -23,7 +23,7 @@ export const integrationRouter = createTRPCRouter({
|
||||
},
|
||||
});
|
||||
|
||||
const access = await getOrganizationAccessCached({
|
||||
const access = await getOrganizationAccess({
|
||||
userId: ctx.session.userId,
|
||||
organizationId: integration.organizationId,
|
||||
});
|
||||
@@ -122,7 +122,7 @@ export const integrationRouter = createTRPCRouter({
|
||||
},
|
||||
});
|
||||
|
||||
const access = await getOrganizationAccessCached({
|
||||
const access = await getOrganizationAccess({
|
||||
userId: ctx.session.userId,
|
||||
organizationId: integration.organizationId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user