mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-04-20 03:50:20 +00:00
feat: implement checkTempIdOrPhone function and update OTP verification logic
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m29s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m29s
This commit is contained in:
parent
4127035471
commit
f3f5800df6
@ -15,6 +15,10 @@ export type FilterUserResponse = {
|
||||
ok: boolean;
|
||||
verified: boolean;
|
||||
};
|
||||
export type FilterTempUserResponse = {
|
||||
ok: boolean;
|
||||
otp_verified: boolean;
|
||||
};
|
||||
|
||||
export async function signin(previousState: ActionState, formData: FormData) {
|
||||
const phoneNumber = formData.get("phoneNumber") as string;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import VerifyRegistrationOTPForm from "@/components/auth/verify-registration-otp-form";
|
||||
import { checkIdOrPhone } from "@/queries/authentication";
|
||||
import ClientErrorMessage from "@/components/client-error-message";
|
||||
import { checkIdOrPhone, checkTempIdOrPhone } from "@/queries/authentication";
|
||||
import { tryCatch } from "@/utils/tryCatch";
|
||||
import Image from "next/image";
|
||||
import { redirect } from "next/navigation";
|
||||
@ -18,12 +19,14 @@ export default async function VerifyRegistrationOTP({
|
||||
"phone number from server page params (verify otp page)",
|
||||
phone_number,
|
||||
);
|
||||
const [error, response] = await tryCatch(checkIdOrPhone({ phone_number }));
|
||||
const [error, response] = await tryCatch(
|
||||
checkTempIdOrPhone({ phone_number }),
|
||||
);
|
||||
if (error) {
|
||||
console.log("Error in checkIdOrPhone", error);
|
||||
return redirect("/auth/signin");
|
||||
return <ClientErrorMessage message={error.message} />;
|
||||
}
|
||||
if (response.verified) redirect("/auth/signin");
|
||||
if (response.otp_verified) redirect("/auth/signin");
|
||||
return (
|
||||
<div className="bg-gray-100 dark:bg-black w-full h-screen flex items-center justify-center font-sans">
|
||||
<div className="flex flex-col items-center justify-center w-full h-full ">
|
||||
|
@ -1,6 +1,7 @@
|
||||
"use server";
|
||||
import {
|
||||
type ActionState,
|
||||
type FilterTempUserResponse,
|
||||
type FilterUserResponse,
|
||||
backendMobileLogin,
|
||||
} from "@/actions/auth-actions";
|
||||
@ -72,6 +73,23 @@ export async function checkIdOrPhone({
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function checkTempIdOrPhone({
|
||||
id_card,
|
||||
phone_number,
|
||||
}: { id_card?: string; phone_number?: string }) {
|
||||
const response = await fetch(
|
||||
`${process.env.SARLINK_API_BASE_URL}/api/auth/users/temp/filter/?id_card=${id_card}&mobile=${phone_number}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
const data = (await response.json()) as FilterTempUserResponse;
|
||||
return data;
|
||||
}
|
||||
|
||||
type TSignupUser = Pick<
|
||||
User,
|
||||
"username" | "address" | "mobile" | "id_card" | "dob"
|
||||
|
Loading…
x
Reference in New Issue
Block a user