2022-01-13 20:05:23 +00:00
|
|
|
import { IdentityProvider } from "@prisma/client";
|
2021-08-18 11:52:25 +00:00
|
|
|
import { compare, hash } from "bcryptjs";
|
2022-01-07 20:23:37 +00:00
|
|
|
import { Session } from "next-auth";
|
|
|
|
import { getSession as getSessionInner, GetSessionParams } from "next-auth/react";
|
2021-03-24 15:03:04 +00:00
|
|
|
|
2022-08-31 20:57:53 +00:00
|
|
|
/** @deprecated use the one from `@calcom/lib/auth` */
|
2021-08-18 11:52:25 +00:00
|
|
|
export async function hashPassword(password: string) {
|
|
|
|
const hashedPassword = await hash(password, 12);
|
|
|
|
return hashedPassword;
|
2021-03-24 15:03:04 +00:00
|
|
|
}
|
2022-08-31 20:57:53 +00:00
|
|
|
/** @deprecated use the one from `@calcom/lib/auth` */
|
2021-08-18 11:52:25 +00:00
|
|
|
export async function verifyPassword(password: string, hashedPassword: string) {
|
|
|
|
const isValid = await compare(password, hashedPassword);
|
|
|
|
return isValid;
|
|
|
|
}
|
2022-08-31 20:57:53 +00:00
|
|
|
/** @deprecated use the one from `@calcom/lib/auth` */
|
2022-01-07 20:23:37 +00:00
|
|
|
export async function getSession(options: GetSessionParams): Promise<Session | null> {
|
2021-08-18 11:52:25 +00:00
|
|
|
const session = await getSessionInner(options);
|
|
|
|
|
|
|
|
// that these are equal are ensured in `[...nextauth]`'s callback
|
2021-08-18 12:15:22 +00:00
|
|
|
return session as Session | null;
|
2021-08-18 11:52:25 +00:00
|
|
|
}
|
2022-08-31 20:57:53 +00:00
|
|
|
/** @deprecated use the one from `@calcom/lib/auth` */
|
2021-09-21 09:29:20 +00:00
|
|
|
export enum ErrorCode {
|
|
|
|
UserNotFound = "user-not-found",
|
|
|
|
IncorrectPassword = "incorrect-password",
|
|
|
|
UserMissingPassword = "missing-password",
|
|
|
|
TwoFactorDisabled = "two-factor-disabled",
|
|
|
|
TwoFactorAlreadyEnabled = "two-factor-already-enabled",
|
|
|
|
TwoFactorSetupRequired = "two-factor-setup-required",
|
|
|
|
SecondFactorRequired = "second-factor-required",
|
|
|
|
IncorrectTwoFactorCode = "incorrect-two-factor-code",
|
|
|
|
InternalServerError = "internal-server-error",
|
|
|
|
NewPasswordMatchesOld = "new-password-matches-old",
|
2022-01-13 20:05:23 +00:00
|
|
|
ThirdPartyIdentityProviderEnabled = "third-party-identity-provider-enabled",
|
2022-08-30 19:58:35 +00:00
|
|
|
RateLimitExceeded = "rate-limit-exceeded",
|
2022-08-30 19:46:52 +00:00
|
|
|
InvalidPassword = "invalid-password",
|
2021-09-21 09:29:20 +00:00
|
|
|
}
|
2022-08-31 20:57:53 +00:00
|
|
|
/** @deprecated use the one from `@calcom/lib/auth` */
|
2022-01-13 20:05:23 +00:00
|
|
|
export const identityProviderNameMap: { [key in IdentityProvider]: string } = {
|
|
|
|
[IdentityProvider.CAL]: "Cal",
|
|
|
|
[IdentityProvider.GOOGLE]: "Google",
|
|
|
|
[IdentityProvider.SAML]: "SAML",
|
|
|
|
};
|