34 lines
899 B
TypeScript
34 lines
899 B
TypeScript
import { Password as DefaultPassword } from '@convex-dev/auth/providers/Password';
|
|
import { DataModel } from '../../../_generated/dataModel';
|
|
import { UseSendOTP, UseSendOTPPasswordReset } from '..';
|
|
import { ConvexError } from 'convex/values';
|
|
|
|
export const Password = DefaultPassword<DataModel>({
|
|
profile(params, ctx) {
|
|
return {
|
|
email: params.email as string,
|
|
name: params.name as string,
|
|
};
|
|
},
|
|
validatePasswordRequirements: (password: string) => {
|
|
if (!validatePassword(password)) {
|
|
throw new ConvexError('Invalid password.');
|
|
}
|
|
},
|
|
reset: UseSendOTPPasswordReset,
|
|
verify: UseSendOTP,
|
|
});
|
|
|
|
export const validatePassword = (password: string): boolean => {
|
|
if (
|
|
password.length < 8 ||
|
|
password.length > 100 ||
|
|
!/\d/.test(password) ||
|
|
!/[a-z]/.test(password) ||
|
|
!/[A-Z]/.test(password)
|
|
) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|