mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-02 16:09:08 +02:00
🐛 Fix handle incorrect 6 digit code
This commit is contained in:
parent
cdcd2a2305
commit
ac1d844b7a
2 changed files with 20 additions and 9 deletions
|
@ -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<{
|
||||
|
|
|
@ -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() ??
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue