mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-04-20 03:50:20 +00:00
feat: integrate backend mobile login and enhance user verification flow
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 6m44s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 6m44s
This commit is contained in:
parent
1e023ebf13
commit
2cb2059f9e
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { signUpFormSchema } from "@/lib/schemas";
|
import { signUpFormSchema } from "@/lib/schemas";
|
||||||
import { backendRegister, checkIdOrPhone } from "@/queries/authentication";
|
import { backendRegister, checkIdOrPhone } from "@/queries/authentication";
|
||||||
import { tryCatch } from "@/utils/tryCatch";
|
import { handleApiResponse, tryCatch } from "@/utils/tryCatch";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
@ -11,7 +11,7 @@ const formSchema = z.object({
|
|||||||
.regex(/^[7|9][0-9]{2}-[0-9]{4}$/, "Please enter a valid phone number"),
|
.regex(/^[7|9][0-9]{2}-[0-9]{4}$/, "Please enter a valid phone number"),
|
||||||
});
|
});
|
||||||
|
|
||||||
type FilterUserResponse = {
|
export type FilterUserResponse = {
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
verified: boolean;
|
verified: boolean;
|
||||||
};
|
};
|
||||||
@ -184,3 +184,19 @@ export const sendOtp = async (phoneNumber: string, code: string) => {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function backendMobileLogin({ mobile }: { mobile: string }) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.SARLINK_API_BASE_URL}/auth/mobile/`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
mobile,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return handleApiResponse<{ detail: string }>(response, "backendMobileLogin");
|
||||||
|
}
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import type { ActionState } from "@/actions/auth-actions";
|
import {
|
||||||
|
type ActionState,
|
||||||
|
type FilterUserResponse,
|
||||||
|
backendMobileLogin,
|
||||||
|
} from "@/actions/auth-actions";
|
||||||
import type { TAuthUser, User } from "@/lib/types/user";
|
import type { TAuthUser, User } from "@/lib/types/user";
|
||||||
import axiosInstance from "@/utils/axiosInstance";
|
import axiosInstance from "@/utils/axiosInstance";
|
||||||
import { handleApiResponse } from "@/utils/tryCatch";
|
import { handleApiResponse, tryCatch } from "@/utils/tryCatch";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export async function login({
|
export async function login({
|
||||||
@ -63,7 +68,7 @@ export async function checkIdOrPhone({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const data = await response.json();
|
const data = (await response.json()) as FilterUserResponse;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +150,31 @@ export async function VerifyRegistrationOTP(
|
|||||||
);
|
);
|
||||||
const data = (await response.json()) as { message: string };
|
const data = (await response.json()) as { message: string };
|
||||||
|
|
||||||
|
const [error, userVerified] = await tryCatch(
|
||||||
|
checkIdOrPhone({ phone_number: mobile as string }),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return {
|
||||||
|
message: "Your account could not be verified. Please contact support.",
|
||||||
|
status: "verify_error",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (userVerified.verified) {
|
||||||
|
const [mobileLoginError, mobileLoginResponse] = await tryCatch(
|
||||||
|
backendMobileLogin({ mobile: mobile as string }),
|
||||||
|
);
|
||||||
|
if (mobileLoginError) {
|
||||||
|
return {
|
||||||
|
message: "Your account could not be verified. Please contact support.",
|
||||||
|
status: "verify_error",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (mobileLoginResponse) {
|
||||||
|
redirect(`/auth/verify-otp?phone_number=${mobile}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: data.message,
|
message: data.message,
|
||||||
status: response.status === 200 ? "success" : "error",
|
status: response.status === 200 ? "success" : "error",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user