Added Connection Component, Store, JWT logic

This commit is contained in:
PxlLoewe
2025-03-14 19:46:09 -07:00
parent d7e4ae468d
commit abf3475c7c
9 changed files with 65 additions and 21 deletions

View File

@@ -0,0 +1,17 @@
import { useSession } from "next-auth/react";
import { connectionStore } from "../../_store/connectionStore";
import { useEffect } from "react";
export const Connection = () => {
const session = useSession();
const cStore = connectionStore((state) => state);
const uid = session.data?.user?.id;
useEffect(() => {
if (uid) {
cStore.connect(uid);
}
}, [uid]);
return <div>{cStore.isConnected ? "Connected" : "Not Connected"}</div>;
};

View File

@@ -6,10 +6,10 @@ import Link from "next/link";
import { connectionStore } from "../../_store/connectionStore";
import { useEffect } from "react";
import { socket } from "../socket";
import { useSession } from "next-auth/react";
import { Connection } from "./Connection";
export default function Navbar() {
const connected = connectionStore((state) => state);
return (
<div className="navbar bg-base-100 shadow-sm">
<div className="flex-1">
@@ -51,6 +51,9 @@ export default function Navbar() {
<path d="M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z" />
</svg>
</label>
<div>
<Connection />
</div>
<div className="dropdown dropdown-end">
<div tabIndex={0} role="button" className="btn btn-ghost">
...

View File

@@ -14,6 +14,7 @@ export default async function RootLayout({
children: React.ReactNode;
}>) {
const session = await getServerSession();
console.log(session);
if (!session) {
redirect("/login");
}

View File

@@ -1,7 +1,5 @@
import { io } from "socket.io-client";
export const socket = io(process.env.NEXT_PUBLIC_DISPATCH_SERVER_URL, {
auth: (cb) => {
cb({ token: "jwt" });
},
autoConnect: false,
});