Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ export const addEmployeeWithoutInvite = async ({
}

let userId = '';
const existingUser = await db.user.findUnique({
const existingUser = await db.user.findFirst({
where: {
email,
email: {
equals: email,
mode: 'insensitive',
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ export function InviteMembersModal({
if (hasEmployeeRoleAndNoAdmin) {
await addEmployeeWithoutInvite({
organizationId,
email: invite.email,
email: invite.email.toLowerCase(),
roles: invite.roles,
});
} else {
// Use authClient to send the invitation
await authClient.organization.inviteMember({
email: invite.email,
email: invite.email.toLowerCase(),
role: invite.roles.length === 1 ? invite.roles[0] : invite.roles,
});
}
Expand Down Expand Up @@ -325,12 +325,12 @@ export function InviteMembersModal({
if (hasEmployeeRoleAndNoAdmin) {
await addEmployeeWithoutInvite({
organizationId,
email,
email: email.toLowerCase(),
roles: validRoles,
});
} else {
await authClient.organization.inviteMember({
email,
email: email.toLowerCase(),
role: validRoles,
});
}
Expand Down
9 changes: 7 additions & 2 deletions apps/app/src/lib/db/employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ export async function completeEmployeeCreation(params: {
console.log(`Starting employee creation for ${email}`);

// Check if the user already exists
const existingUser = await db.user.findUnique({
where: { email },
const existingUser = await db.user.findFirst({
where: {
email: {
equals: email,
mode: 'insensitive',
},
},
});

let employee: Member;
Expand Down
4 changes: 3 additions & 1 deletion apps/portal/src/app/components/otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export function OtpSignIn({ className }: Props) {
if (error) {
setLoading(false);
toast.error(error.message);
setSent(false);
} else {
setSent(true);
}

setSent(true);
setLoading(false);
}

Expand Down
2 changes: 2 additions & 0 deletions apps/portal/src/app/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const auth = betterAuth({
emailOTP({
otpLength: 6,
expiresIn: 10 * 60,
// Prevent automatic user creation on OTP sign-in
disableSignUp: true,
async sendVerificationOTP({ email, otp }) {
await sendEmail({
to: email,
Expand Down
Loading