Files
documenso/packages/auth/server/lib/session.ts
Mythie 7009995204 wip
2025-01-06 14:44:20 +11:00

31 lines
648 B
TypeScript

import { prisma } from '@documenso/prisma';
import { AuthenticationErrorCode } from '../error-codes';
import { AuthenticationError } from '../errors';
export const getSession = async (token: string) => {
const result = await prisma.session.findUnique({
where: {
sessionToken: token,
},
include: {
user: true,
},
});
if (!result) {
throw new AuthenticationError(AuthenticationErrorCode.SessionNotFound);
}
if (result.expires < new Date()) {
throw new AuthenticationError(AuthenticationErrorCode.SessionExpired);
}
const { user, ...session } = result;
return {
session,
user,
};
};