fix: error when session expired
This commit is contained in:
@@ -75,7 +75,6 @@ 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
|
||||
@@ -226,9 +225,7 @@ export const authRouter = createTRPCRouter({
|
||||
|
||||
const token = generateSessionToken();
|
||||
const session = await createSession(token, user.id);
|
||||
console.log('session', session);
|
||||
setSessionTokenCookie(ctx.setCookie, token, session.expiresAt);
|
||||
console.log('ctx.setCookie', ctx.setCookie);
|
||||
return {
|
||||
type: 'email',
|
||||
};
|
||||
@@ -335,7 +332,6 @@ 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 {
|
||||
|
||||
@@ -95,7 +95,8 @@ const enforceUserIsAuthed = t.middleware(async ({ ctx, next }) => {
|
||||
|
||||
// Only used on protected routes
|
||||
const enforceAccess = t.middleware(async ({ ctx, next, type, getRawInput }) => {
|
||||
return runWithAlsSession(ctx.session.session?.id, async () => {
|
||||
const sessionId = ctx.session?.session?.id ?? null;
|
||||
return runWithAlsSession(sessionId, async () => {
|
||||
const rawInput = await getRawInput();
|
||||
if (type === 'mutation' && process.env.DEMO_USER_ID) {
|
||||
throw new TRPCError({
|
||||
@@ -153,7 +154,7 @@ const loggerMiddleware = t.middleware(
|
||||
);
|
||||
|
||||
const sessionScopeMiddleware = t.middleware(async ({ ctx, next }) => {
|
||||
const sessionId = ctx.session.session?.id ?? null;
|
||||
const sessionId = ctx.session?.session?.id ?? null;
|
||||
return runWithAlsSession(sessionId, async () => {
|
||||
return next();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user