All files / apps/web/src/handlers/user logout.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20        6x           1x 1x       1x        
import { AUTH_COOKIE } from "~app/utils/auth";
import { authProcedure } from "~web/handlers/trpc";
import { setCookie } from "~web/utils/cookies";
 
export const procedure = authProcedure
	.meta({
		title: "Log out",
		description: "Ends the current session and clears the auth cookie.",
	})
	.mutation(async ({ ctx }) => {
		const { database } = ctx;
		await database
			.deleteFrom("sessions")
			.where("sessionId", "=", ctx.authToken)
			.executeTakeFirst();
		setCookie(ctx, AUTH_COOKIE, "", {
			expires: Temporal.Now.zonedDateTimeISO(),
		});
	});