mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-09 18:58:46 -06:00
Move repository into a monorepo with turborepo and pnpm. This is a big change in the way the code is organized, used and deployed.
29 lines
779 B
TypeScript
29 lines
779 B
TypeScript
import { compare, hash } from "bcryptjs";
|
|
|
|
export async function hashPassword(password: string) {
|
|
const hashedPassword = await hash(password, 12);
|
|
return hashedPassword;
|
|
}
|
|
|
|
export async function verifyPassword(password: string, hashedPassword: string) {
|
|
const isValid = await compare(password, hashedPassword);
|
|
return isValid;
|
|
}
|
|
export function requireAuthentication(gssp) {
|
|
return async (context) => {
|
|
const { req, resolvedUrl } = context;
|
|
const token = req.cookies.userToken;
|
|
|
|
if (!token) {
|
|
return {
|
|
redirect: {
|
|
destination: `/auth/signin?callbackUrl=${encodeURIComponent(resolvedUrl)}`,
|
|
statusCode: 302,
|
|
},
|
|
};
|
|
}
|
|
|
|
return await gssp(context); // Continue on to call `getServerSideProps` logic
|
|
};
|
|
}
|