Skip to content

Commit

Permalink
Merge pull request #1152 from Open-Earth-Foundation/fix/email-redirec…
Browse files Browse the repository at this point in the history
…t-url

Fix/email redirect url
  • Loading branch information
cephaschapa authored Feb 24, 2025
2 parents 3a0d3af + 055057a commit 0cf43c3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions app/src/app/[lng]/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ export default function Login({
}
};

// Extract doesInvitedUserExist from callback params\
// If it is true, redirect to /user/invites page
// If it is false, redirect to /auth/signup page
// Check if the callbackUrl contains a query string
const hasQueryString = callbackUrl.includes("?");
// Split the URL into path and query string (if query string exists)
const [path, queryString] = hasQueryString
? callbackUrl.split("?")
: [callbackUrl, ""];
const callbackUrlParams = new URLSearchParams(queryString);
const doesInvitedUserExist = callbackUrlParams.get("doesInvitedUserExist");

if (doesInvitedUserExist && doesInvitedUserExist !== "true") {
// remove the doesInvitedUserExist param from the callbackUrl
callbackUrlParams.delete("doesInvitedUserExist");
const updatedCallbackUrl = `${path}?${callbackUrlParams.toString()}`;
return router.push(
"/auth/signup/?callbackUrl=" + encodeURIComponent(updatedCallbackUrl),
);
}

return (
<Box>
<Heading size="xl">{t("login-heading")}</Heading>
Expand Down
17 changes: 16 additions & 1 deletion app/src/app/api/v0/user/invites/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,23 @@ export const POST = apiHandler(async (req, { params, session }) => {
}
}),
);
// Check if invited user exists then flag that user if they don't exist in the database

const doesInvitedUserExist = await db.models.User.findOne({
where: { email },
});
const host = process.env.HOST ?? "http://localhost:3000";
const url = `${host}/user/invites?cityIds=${encodeURIComponent(invites.map((i) => i.cityId).join(","))}&token=${encodeURIComponent(invitationCode)}&email=${encodeURIComponent(email)}`;
const params = new URLSearchParams();

// Add query parameters
params.set("cityIds", invites.map((i) => i.cityId).join(","));
params.set("token", invitationCode);
params.set("email", email);
params.set(
"doesInvitedUserExist",
doesInvitedUserExist ? "true" : "false",
);
const url = `${host}/user/invites?${params.toString()}`;
const sendInvite = await sendEmail({
to: email!,
subject: "City Catalyst - City Invitation",
Expand Down

0 comments on commit 0cf43c3

Please sign in to comment.