Skip to content

Commit

Permalink
Try Personio login with switched names after fail
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikSchmidt committed Mar 19, 2024
1 parent 22a04ea commit e74b155
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/apis/personio/PersonioApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,20 @@ export async function initializePersonioApi(
const mailAddress = `${username}@${DIGITALSERVICE_MAIL_DOMAIN}`;
url.searchParams.set("email", mailAddress);

const employeeData = (await fetchWithPersonioAuth(
url,
)) as PersonioApiEmployees;
let employeeData = await fetchWithPersonioAuth(url);

if (!employeeData.success) {
// Try with switched first and last name
const [lastName, firstName] = username.split(".");
const mailAddress = `${firstName}.${lastName}@${DIGITALSERVICE_MAIL_DOMAIN}`;
url.searchParams.set("email", mailAddress);

employeeData = await fetchWithPersonioAuth(url);
}

if (!employeeData.success) {
throw new Error("Personio employee not found");
}

const schedule =
employeeData.data[0].attributes.work_schedule.value.attributes;
Expand Down
8 changes: 8 additions & 0 deletions app/routes/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export async function action({ request }: ActionFunctionArgs) {
return json({
message: "Login failed! Please check your username & password.",
});
} else if (
error instanceof Error &&
error.message === "Personio employee not found"
) {
return json({
message:
"Personio employee not found, make sure that your Troi username matches your Digitalservice email address.",
});
} else {
throw error;
}
Expand Down

0 comments on commit e74b155

Please sign in to comment.