Skip to content

Commit

Permalink
recheck settings
Browse files Browse the repository at this point in the history
  • Loading branch information
peintnermax committed Jan 9, 2025
1 parent 3809b8d commit 36b6362
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions apps/login/src/lib/server/loginname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,40 @@ export async function sendLoginname(command: SendLoginnameCommand) {
user.details?.resourceOwner,
);

// recheck login settings after user discovery, as the search might have been done without org scope
if (
userLoginSettings?.disableLoginWithEmail &&
userLoginSettings?.disableLoginWithPhone
) {
if (user.username !== command.loginName) {
return { error: "User not found in the system!" };
}
} else if (userLoginSettings?.disableLoginWithEmail) {
const humanUser =
potentialUsers[0].type.case === "human"
? potentialUsers[0].type.value
: undefined;

if (
user.username !== command.loginName ||
humanUser?.phone?.phone !== command.loginName
) {
return { error: "User not found in the system!" };
}
} else if (userLoginSettings?.disableLoginWithPhone) {
const humanUser =
potentialUsers[0].type.case === "human"
? potentialUsers[0].type.value
: undefined;

if (
user.username !== command.loginName ||
humanUser?.email?.email !== command.loginName
) {
return { error: "User not found in the system!" };
}
}

const checks = create(ChecksSchema, {
user: { search: { case: "userId", value: userId } },
});
Expand Down

0 comments on commit 36b6362

Please sign in to comment.