mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
api auth and todo
This commit is contained in:
0
packages/lib/mail/index.ts
Normal file
0
packages/lib/mail/index.ts
Normal file
0
packages/lib/mail/sendSigningRequestMail.ts
Normal file
0
packages/lib/mail/sendSigningRequestMail.ts
Normal file
2
packages/lib/mail/sendSigningStatusChangedMail.ts
Normal file
2
packages/lib/mail/sendSigningStatusChangedMail.ts
Normal file
@ -0,0 +1,2 @@
|
||||
// nodemailer
|
||||
// sendgrid
|
||||
30
packages/lib/server/getUserFromToken.ts
Normal file
30
packages/lib/server/getUserFromToken.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import prisma from "@documenso/prisma";
|
||||
import { User as PrismaUser } from "@prisma/client";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
export async function getUserFromToken(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
): Promise<PrismaUser | null> {
|
||||
const token = await getToken({ req });
|
||||
const tokenEmail = token?.email?.toString();
|
||||
|
||||
if (!token) {
|
||||
res.status(401).send("No token found for request.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!tokenEmail) {
|
||||
res.status(400).send("No email found in token.");
|
||||
return null;
|
||||
}
|
||||
|
||||
let user = await prisma.user.findFirst({
|
||||
where: { email: tokenEmail },
|
||||
});
|
||||
|
||||
if (user) return user;
|
||||
if (!user) res.status(401).send("No user found for token.");
|
||||
return null;
|
||||
}
|
||||
@ -2,3 +2,4 @@ export { defaultHandler } from "./defaultHandler";
|
||||
export { defaultResponder } from "./defaultResponder";
|
||||
export { HttpError } from "./http-error";
|
||||
export { getServerErrorFromUnknown } from "./getServerErrorFromUnknown";
|
||||
export { getUserFromToken } from "./getUserFromToken";
|
||||
|
||||
Reference in New Issue
Block a user