diff --git a/actions/auth-actions.ts b/actions/auth-actions.ts
index 564de7b..9541682 100644
--- a/actions/auth-actions.ts
+++ b/actions/auth-actions.ts
@@ -10,6 +10,11 @@ const formSchema = z.object({
.regex(/^[7|9][0-9]{2}-[0-9]{4}$/, "Please enter a valid phone number"),
});
+type FilterUserResponse = {
+ ok: boolean;
+ verified: boolean;
+};
+
export async function signin(previousState: ActionState, formData: FormData) {
const phoneNumber = formData.get("phoneNumber") as string;
const result = formSchema.safeParse({ phoneNumber });
@@ -31,7 +36,28 @@ export async function signin(previousState: ActionState, formData: FormData) {
const FORMATTED_MOBILE_NUMBER: string = `${phoneNumber.split("-").join("")}`;
console.log({ FORMATTED_MOBILE_NUMBER });
- const userExistsResponse = await fetch(
+ const user = await fetch(
+ `${process.env.SARLINK_API_BASE_URL}/api/auth/users/filter/?mobile=${FORMATTED_MOBILE_NUMBER}`,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ },
+ );
+ const userData = (await user.json()) as FilterUserResponse;
+ if (!userData?.ok) {
+ return redirect(`/auth/signup?phone_number=${phoneNumber}`);
+ }
+ if (!userData.verified) {
+ return {
+ message:
+ "Your account is on pending verification. Please wait for a response from admin or contact shihaam.",
+ status: "error",
+ };
+ }
+
+ const sendOTPResponse = await fetch(
`${process.env.SARLINK_API_BASE_URL}/auth/mobile/`,
{
method: "POST",
@@ -43,23 +69,10 @@ export async function signin(previousState: ActionState, formData: FormData) {
}),
},
);
- const userExists = await userExistsResponse.json();
- console.log("user exists", userExists);
- if (userExists?.non_field_errors) {
- return redirect(`/signup?phone_number=${phoneNumber}`);
- }
+ const otpResponse = await sendOTPResponse.json();
+ console.log("otpResponse", otpResponse);
- if (!userExists?.verified)
- return {
- message:
- "Your account is on pending verification. Please wait for a response from admin or contact shihaam.",
- status: "error",
- };
-
- // await authClient.phoneNumber.sendOtp({
- // phoneNumber: NUMBER_WITH_COUNTRY_CODE,
- // });
- redirect(`/verify-otp?phone_number=${FORMATTED_MOBILE_NUMBER}`);
+ redirect(`/auth/verify-otp?phone_number=${FORMATTED_MOBILE_NUMBER}`);
}
type ActionState = {
diff --git a/actions/omada-actions.ts b/actions/omada-actions.ts
index 8f02359..4638677 100644
--- a/actions/omada-actions.ts
+++ b/actions/omada-actions.ts
@@ -1,6 +1,5 @@
"use server";
-import prisma from "@/lib/db";
import type { GroupProfile, MacAddress, OmadaResponse } from "@/lib/types";
import { formatMacAddress } from "@/lib/utils";
import { revalidatePath } from "next/cache";
@@ -124,11 +123,11 @@ export async function blockDevice({
if (!macAddress) {
throw new Error("macAddress is a required parameter");
}
- const device = await prisma.device.findFirst({
- where: {
- mac: macAddress,
- },
- });
+ // const device = await prisma.device.findFirst({
+ // where: {
+ // mac: macAddress,
+ // },
+ // });
try {
const baseUrl: string = process.env.OMADA_BASE_URL || "";
const url: string = `${baseUrl}/api/v2/sites/${process.env.OMADA_SITE_ID}/cmd/clients/${formatMacAddress(macAddress)}/${type}`;
@@ -146,16 +145,16 @@ export async function blockDevice({
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
- await prisma.device.update({
- where: {
- id: device?.id,
- },
- data: {
- reasonForBlocking: type === "block" ? reason : "",
- blocked: type === "block",
- blockedBy: blockedBy,
- },
- });
+ // await prisma.device.update({
+ // where: {
+ // id: device?.id,
+ // },
+ // data: {
+ // reasonForBlocking: type === "block" ? reason : "",
+ // blocked: type === "block",
+ // blockedBy: blockedBy,
+ // },
+ // });
revalidatePath("/parental-control");
} catch (error) {
console.error("Error blocking device:", error);
diff --git a/app/(auth)/auth/signin/page.tsx b/app/(auth)/auth/signin/page.tsx
index 1b9f7dd..51792f6 100644
--- a/app/(auth)/auth/signin/page.tsx
+++ b/app/(auth)/auth/signin/page.tsx
@@ -1,9 +1,5 @@
import LoginForm from "@/components/auth/login-form";
-import { auth } from "@/app/auth";
-import { headers } from "next/headers";
import Image from "next/image";
-import { redirect } from "next/navigation";
-import React from "react";
export default async function LoginPage() {
return (
diff --git a/app/(dashboard)/devices/page.tsx b/app/(dashboard)/devices/page.tsx
index 1161025..97500c8 100644
--- a/app/(dashboard)/devices/page.tsx
+++ b/app/(dashboard)/devices/page.tsx
@@ -1,12 +1,10 @@
+import { authOptions } from "@/app/auth";
import { DevicesTable } from "@/components/devices-table";
import Search from "@/components/search";
import AddDeviceDialogForm from "@/components/user/add-device-dialog";
-import { getCurrentUser } from "@/lib/auth-utils";
+import { getServerSession } from "next-auth";
import React, { Suspense } from "react";
-
-
-
export default async function Devices({
searchParams,
}: {
@@ -18,14 +16,12 @@ export default async function Devices({
}>;
}) {
const query = (await searchParams)?.query || "";
- const user = await getCurrentUser()
+ const session = await getServerSession(authOptions);
return (
-
- My Devices
-
-
+
My Devices
+
-
diff --git a/components/auth/account-popver.tsx b/components/auth/account-popver.tsx
index 0349344..e55aa1e 100644
--- a/components/auth/account-popver.tsx
+++ b/components/auth/account-popver.tsx
@@ -1,56 +1,54 @@
-'use client'
-import { Button } from "@/components/ui/button"
+"use client";
+import { Button } from "@/components/ui/button";
import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/components/ui/popover"
-import { authClient } from "@/lib/auth-client";
-import { Loader2, User as UserIcon } from "lucide-react"
-import { useRouter } from "next/navigation"
-import { useState } from "react"
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { Loader2, User as UserIcon } from "lucide-react";
+import { signOut, useSession } from "next-auth/react";
+import { useRouter } from "next/navigation";
+import { useState } from "react";
export function AccountPopover() {
- const session = authClient.useSession();
- const [loading, setLoading] = useState(false)
- const router = useRouter()
+ const session = useSession();
+ const [loading, setLoading] = useState(false);
+ const router = useRouter();
- if (session.isPending) {
-
- }
- return (
-
-
-
-
-
-
-
-
-
{session.data?.user?.name}
-
- {session.data?.user?.phoneNumber}
-
-
-
-
-
-
- )
+ if (session.status === "loading") {
+ ;
+ }
+ return (
+
+
+
+
+
+
+
+
+ {session.data?.user?.name}
+
+
+ {session.data?.user?.phoneNumber}
+
+
+
+
+
+
+ );
}
diff --git a/components/auth/application-layout.tsx b/components/auth/application-layout.tsx
index f4bf083..8e0ca93 100644
--- a/components/auth/application-layout.tsx
+++ b/components/auth/application-layout.tsx
@@ -4,33 +4,26 @@ import { Wallet } from "@/components/wallet";
import { ModeToggle } from "@/components/theme-toggle";
import { AppSidebar } from "@/components/ui/app-sidebar";
+import { authOptions } from "@/app/auth";
import { Separator } from "@/components/ui/separator";
import {
SidebarInset,
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar";
-import { auth } from "@/app/auth";
-import prisma from "@/lib/db";
+import { getServerSession } from "next-auth";
import { headers } from "next/headers";
import { AccountPopover } from "./account-popver";
export async function ApplicationLayout({
children,
}: { children: React.ReactNode }) {
- const session = await auth.api.getSession({
- headers: await headers(),
- });
- const billFormula = await prisma.billFormula.findFirst();
- const user = await prisma.user.findFirst({
- where: {
- id: session?.user?.id,
- },
- });
+ const session = await getServerSession(authOptions);
+
return (
-
-
+
+ {/* */}
-