mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-10 18:58:44 -06:00
* make all env variables required at build time * update env files * add .env.docker file with basic docker configuration * update Readme with new instructions
25 lines
577 B
TypeScript
25 lines
577 B
TypeScript
import jwt from "jsonwebtoken";
|
|
import { prisma } from "database";
|
|
|
|
export function createToken(userId, userEmail, options = {}) {
|
|
return jwt.sign({ id: userId }, process.env.NEXTAUTH_SECRET + userEmail, options);
|
|
}
|
|
|
|
export async function verifyToken(token, userEmail = "") {
|
|
if (!userEmail) {
|
|
const { id } = jwt.decode(token);
|
|
|
|
const foundUser = await prisma.user.findUnique({
|
|
where: { id },
|
|
});
|
|
|
|
if (!foundUser) {
|
|
return null;
|
|
}
|
|
|
|
userEmail = foundUser.email;
|
|
}
|
|
|
|
return jwt.verify(token, process.env.NEXTAUTH_SECRET + userEmail);
|
|
}
|