Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Fix handle incorrect 6 digit code

Luke Vellaac1d844b7aba
diff --git a/apps/web/src/components/auth/auth-forms.tsx b/apps/web/src/components/auth/auth-forms.tsx
index edad2e027..46e0df910 100644
--- a/apps/web/src/components/auth/auth-forms.tsx
+++ b/apps/web/src/components/auth/auth-forms.tsx
@@ -7,6 +7,7 @@ import React from "react";
import { useForm } from "react-hook-form";
import { createGlobalState } from "react-use";
+import { absoluteUrl } from "@/utils/absolute-url";
import { usePostHog } from "@/utils/posthog";
import { trpc } from "@/utils/trpc/client";
@@ -16,10 +17,11 @@ import { TextInput } from "../text-input";
export const useDefaultEmail = createGlobalState("");
const verifyCode = async (options: { email: string; token: string }) => {
- const res = await fetch(
- "/api/auth/callback/email?" + new URLSearchParams(options),
- );
- return res.status === 200;
+ const url = absoluteUrl("/api/auth/callback/email", options);
+
+ const res = await fetch(url);
+
+ return !res.url.includes("auth/error");
};
export const VerifyCode: React.FunctionComponent<{
diff --git a/apps/web/src/utils/absolute-url.ts b/apps/web/src/utils/absolute-url.ts
index 6dd353603..734e2b928 100644
--- a/apps/web/src/utils/absolute-url.ts
+++ b/apps/web/src/utils/absolute-url.ts
@@ -15,12 +15,21 @@ function joinPath(baseUrl: string, subpath = "") {
return baseUrl;
}
+export function objectToQueryString(obj: Record<string, string>) {
+ const parts = [];
+ for (const key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ const value = obj[key];
+ if (value !== undefined) {
+ parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
+ }
+ }
+ }
+ return parts.join("&");
+}
export function absoluteUrl(subpath = "", query?: Record<string, string>) {
- const queryString = query
- ? `?${Object.entries(query)
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
- .join("&")}`
- : "";
+ const queryString = query ? `?${objectToQueryString(query)}` : "";
+
const baseUrl =
process.env.NEXT_PUBLIC_BASE_URL ??
getVercelUrl() ??