+
+
+ {open && (
+ <>
+ {/* Backdrop */}
+
setOpen(false)} />
+ {/* Panel */}
+
+
+ Room Settings
+
+
+ {removeError && (
+
{removeError}
+ )}
+
+
+
+ {/* Danger zone */}
+
+
+
+
+ >
+ )}
+
+ );
+}
diff --git a/app/(auth)/rooms/actions.ts b/app/(auth)/rooms/actions.ts
new file mode 100644
index 0000000..c060345
--- /dev/null
+++ b/app/(auth)/rooms/actions.ts
@@ -0,0 +1,82 @@
+"use server";
+
+import { revalidatePath } from "next/cache";
+import { redirect } from "next/navigation";
+import {
+ createRoom,
+ addMember,
+ deleteRoom,
+ removeMember,
+} from "@/utils/rooms/rooms";
+import { UUID_REGEX } from "@/utils/validation";
+
+export type CreateRoomState = {
+ error?: string;
+} | null;
+
+export async function createRoomAction(
+ _prevState: CreateRoomState,
+ formData: FormData,
+): Promise
{
+ const name = formData.get("name");
+ if (typeof name !== "string" || !name.trim()) {
+ return { error: "Room name is required." };
+ }
+
+ const result = await createRoom(name.trim());
+ if (result.error) {
+ return { error: result.error };
+ }
+
+ revalidatePath("/rooms");
+ redirect(`/rooms/${result.roomId}`);
+}
+
+export type AddMemberState = {
+ success?: boolean;
+ error?: string;
+} | null;
+
+export async function addMemberAction(
+ roomId: string,
+ _prevState: AddMemberState,
+ formData: FormData,
+): Promise {
+ const userId = formData.get("userId");
+ if (typeof userId !== "string" || !userId.trim()) {
+ return { error: "User ID is required." };
+ }
+
+ const trimmed = userId.trim();
+ if (!UUID_REGEX.test(trimmed)) {
+ return { error: "Please enter a valid user ID (UUID format)." };
+ }
+
+ const result = await addMember(roomId, trimmed);
+ if (result.error) {
+ return { error: result.error };
+ }
+
+ revalidatePath("/rooms");
+ return { success: true };
+}
+
+export async function deleteRoomAction(roomId: string) {
+ const result = await deleteRoom(roomId);
+ if (result.error) {
+ return { error: result.error };
+ }
+
+ revalidatePath("/rooms");
+ redirect("/rooms");
+}
+
+export async function removeMemberAction(roomId: string, userId: string) {
+ const result = await removeMember(roomId, userId);
+ if (result.error) {
+ return { error: result.error };
+ }
+
+ revalidatePath(`/rooms/${roomId}`);
+ return { success: true };
+}
diff --git a/app/(auth)/rooms/add-member-form.tsx b/app/(auth)/rooms/add-member-form.tsx
new file mode 100644
index 0000000..b9e8277
--- /dev/null
+++ b/app/(auth)/rooms/add-member-form.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import { useActionState } from "react";
+import { addMemberAction, type AddMemberState } from "./actions";
+
+const initialState: AddMemberState = null;
+
+export function AddMemberForm({ roomId }: { roomId: string }) {
+ const boundAction = addMemberAction.bind(null, roomId);
+ const [state, action, pending] = useActionState(boundAction, initialState);
+
+ return (
+
+ );
+}
diff --git a/app/(auth)/rooms/create-room-form.tsx b/app/(auth)/rooms/create-room-form.tsx
new file mode 100644
index 0000000..cdcfc84
--- /dev/null
+++ b/app/(auth)/rooms/create-room-form.tsx
@@ -0,0 +1,42 @@
+"use client";
+
+import { useActionState } from "react";
+import { createRoomAction, type CreateRoomState } from "./actions";
+
+const initialState: CreateRoomState = null;
+
+export function CreateRoomForm() {
+ const [state, action, pending] = useActionState(
+ createRoomAction,
+ initialState,
+ );
+
+ return (
+
+ );
+}
diff --git a/app/(auth)/rooms/page.tsx b/app/(auth)/rooms/page.tsx
new file mode 100644
index 0000000..ff160a3
--- /dev/null
+++ b/app/(auth)/rooms/page.tsx
@@ -0,0 +1,27 @@
+import { listRooms } from "@/utils/rooms/rooms";
+import { CreateRoomForm } from "./create-room-form";
+import { RoomsList, type RoomEntry } from "./rooms-list";
+
+export default async function RoomsPage() {
+ const rawRooms = await listRooms();
+ const rooms: RoomEntry[] = rawRooms ?? [];
+
+ return (
+
+
Rooms
+
+ Your conversations will appear here.
+
+
+
+ {/* Create room */}
+
+
+
+
+ {/* Rooms list */}
+
+
+
+ );
+}
diff --git a/app/(auth)/rooms/rooms-list.tsx b/app/(auth)/rooms/rooms-list.tsx
new file mode 100644
index 0000000..9cc2f5f
--- /dev/null
+++ b/app/(auth)/rooms/rooms-list.tsx
@@ -0,0 +1,75 @@
+import Link from "next/link";
+
+export interface RoomEntry {
+ id: string;
+ name: string;
+ created_at: string;
+ member_count: number;
+}
+
+export function RoomsList({ rooms }: { rooms: RoomEntry[] }) {
+ if (rooms.length === 0) {
+ return (
+
+ );
+ }
+
+ return (
+
+
+ Your Rooms
+
+ {rooms.length}
+
+
+
+ {rooms.map((room) => (
+ -
+
+
+
+ {room.name}
+
+
+ {room.member_count}{" "}
+ {room.member_count === 1 ? "member" : "members"}
+
+
+
+
+
+ ))}
+
+
+ );
+}
diff --git a/app/(auth)/sidebar.tsx b/app/(auth)/sidebar.tsx
new file mode 100644
index 0000000..1f92b1a
--- /dev/null
+++ b/app/(auth)/sidebar.tsx
@@ -0,0 +1,165 @@
+"use client";
+
+import Link from "next/link";
+import { usePathname } from "next/navigation";
+import { signOut } from "@/utils/profile/profile";
+import Image from "next/image";
+
+const navItems = [
+ {
+ label: "Rooms",
+ href: "/rooms",
+ icon: (
+
+ ),
+ },
+ {
+ label: "Friends",
+ href: "/friends",
+ icon: (
+
+ ),
+ },
+ {
+ label: "Profile",
+ href: "/profile",
+ icon: (
+
+ ),
+ },
+];
+
+export function Sidebar({
+ displayName,
+ email,
+ avatarUrl,
+}: {
+ displayName: string;
+ email: string;
+ avatarUrl: string;
+}) {
+ const pathname = usePathname();
+ return (
+
+ );
+}
diff --git a/app/globals.css b/app/globals.css
index a2dc41e..7267fcc 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -1,26 +1,19 @@
@import "tailwindcss";
:root {
- --background: #ffffff;
- --foreground: #171717;
-}
-
-@theme inline {
- --color-background: var(--background);
- --color-foreground: var(--foreground);
- --font-sans: var(--font-geist-sans);
- --font-mono: var(--font-geist-mono);
+ --background: #ffffff;
+ --foreground: #171717;
}
@media (prefers-color-scheme: dark) {
- :root {
- --background: #0a0a0a;
- --foreground: #ededed;
- }
+ :root {
+ --background: #0a0a0a;
+ --foreground: #ededed;
+ }
}
body {
- background: var(--background);
- color: var(--foreground);
- font-family: Arial, Helvetica, sans-serif;
+ background: var(--background);
+ color: var(--foreground);
+ font-family: Arial, Helvetica, sans-serif;
}
diff --git a/app/layout.tsx b/app/layout.tsx
index 976eb90..d4294f4 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -13,8 +13,8 @@ const geistMono = Geist_Mono({
});
export const metadata: Metadata = {
- title: "Create Next App",
- description: "Generated by create next app",
+ title: "Fastchat",
+ description: "A real-time encrypted chat application",
};
export default function RootLayout({
diff --git a/app/login/actions.ts b/app/login/actions.ts
new file mode 100644
index 0000000..3b0489c
--- /dev/null
+++ b/app/login/actions.ts
@@ -0,0 +1,35 @@
+"use server";
+
+import { redirect } from "next/navigation";
+import { login } from "@/utils/authentication/signin";
+
+export type LoginState = {
+ error?: string;
+} | null;
+
+export async function loginAction(
+ _prevState: LoginState,
+ formData: FormData,
+): Promise {
+ const email = formData.get("email");
+ const password = formData.get("password");
+ const next = formData.get("next");
+
+ if (typeof email !== "string" || typeof password !== "string") {
+ return { error: "Email and password are required." };
+ }
+
+ try {
+ const result = await login(email, password);
+ if (result?.error) {
+ return { error: result.error.message ?? "Login failed." };
+ }
+ } catch (error) {
+ const message = error instanceof Error ? error.message : "Login failed.";
+ return { error: message };
+ }
+
+ const redirectTo =
+ typeof next === "string" && next.startsWith("/") ? next : "/profile";
+ redirect(redirectTo);
+}
diff --git a/app/login/login-form.tsx b/app/login/login-form.tsx
new file mode 100644
index 0000000..8832757
--- /dev/null
+++ b/app/login/login-form.tsx
@@ -0,0 +1,70 @@
+"use client";
+
+import Link from "next/link";
+import { useActionState } from "react";
+import { loginAction, type LoginState } from "./actions";
+
+const initialState: LoginState = null;
+
+export default function LoginForm({ next }: { next?: string }) {
+ const [state, action, pending] = useActionState(loginAction, initialState);
+
+ return (
+
+
+
Log in
+
+ Sign in to start chatting with your friends.
+
+
+
+
+ Don't have an account?{" "}
+
+ Register
+
+
+
+ );
+}
diff --git a/app/login/page.tsx b/app/login/page.tsx
new file mode 100644
index 0000000..7a52cc8
--- /dev/null
+++ b/app/login/page.tsx
@@ -0,0 +1,14 @@
+import LoginForm from "./login-form";
+
+export default async function LoginPage({
+ searchParams,
+}: {
+ searchParams: Promise<{ next?: string }>;
+}) {
+ const { next } = await searchParams;
+ return (
+
+
+
+ );
+}
diff --git a/app/page.tsx b/app/page.tsx
index 13eccca..7331fc1 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -1,102 +1,5 @@
-import Image from "next/image";
-import changeBasePath from "@/utils/assets/basepath";
+import { redirect } from "next/navigation";
export default function Home() {
- return (
-
-
-
-
- -
- Get started by editing{" "}
-
- app/page.tsx
-
- .
-
- - Save and see your changes instantly.
-
-
-
-
-
-
- );
+ redirect("/profile");
}
diff --git a/app/register/actions.ts b/app/register/actions.ts
new file mode 100644
index 0000000..63a9a86
--- /dev/null
+++ b/app/register/actions.ts
@@ -0,0 +1,31 @@
+"use server";
+
+import { signup } from "@/utils/authentication/register";
+
+export type RegisterState = {
+ error?: string;
+} | null;
+
+export async function registerAction(
+ _prevState: RegisterState,
+ formData: FormData,
+): Promise {
+ const email = formData.get("email");
+ const password = formData.get("password");
+
+ if (typeof email !== "string" || typeof password !== "string") {
+ return { error: "Email and password are required." };
+ }
+
+ try {
+ const result = await signup(email, password);
+ if (result?.error) {
+ return { error: result.error.message ?? "Registration failed." };
+ }
+ } catch (error) {
+ const message = error instanceof Error ? error.message : "Registration failed.";
+ return { error: message };
+ }
+
+ return null;
+}
diff --git a/app/register/page.tsx b/app/register/page.tsx
new file mode 100644
index 0000000..3a9c1b3
--- /dev/null
+++ b/app/register/page.tsx
@@ -0,0 +1,9 @@
+import RegisterForm from "./register-form";
+
+export default function RegisterPage() {
+ return (
+
+
+
+ );
+}
diff --git a/app/register/register-form.tsx b/app/register/register-form.tsx
new file mode 100644
index 0000000..92fc740
--- /dev/null
+++ b/app/register/register-form.tsx
@@ -0,0 +1,69 @@
+"use client";
+
+import Link from "next/link";
+import { useActionState } from "react";
+import { registerAction, type RegisterState } from "./actions";
+
+const initialState: RegisterState = null;
+
+export default function RegisterForm() {
+ const [state, action, pending] = useActionState(
+ registerAction,
+ initialState,
+ );
+
+ return (
+
+
+
Create an account
+
+ Sign up to start chatting with your friends.
+
+
+
+
+ Already have an account?{" "}
+
+ Log in
+
+
+
+ );
+}
diff --git a/bun.lock b/bun.lock
index 98e685b..a37ce09 100644
--- a/bun.lock
+++ b/bun.lock
@@ -7,6 +7,7 @@
"dependencies": {
"@supabase/ssr": "^0.10.3",
"next": "16.2.6",
+ "qrcode.react": "^4.2.0",
"react": "19.2.4",
"react-dom": "19.2.4",
},
@@ -735,6 +736,8 @@
"punycode": ["punycode@2.3.1", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="],
+ "qrcode.react": ["qrcode.react@4.2.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-QpgqWi8rD9DsS9EP3z7BT+5lY5SFhsqGjpgW5DY/i3mK4M9DTBNz3ErMi8BWYEfI3L0d8GIbGmcdFAS1uIRGjA=="],
+
"queue-microtask": ["queue-microtask@1.2.3", "", {}, "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="],
"react": ["react@19.2.4", "", {}, "sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ=="],
diff --git a/next.config.ts b/next.config.ts
index 70f8a62..6aa68c0 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -3,6 +3,17 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = {
output: "standalone",
basePath: process.env.BASE_PATH,
+ allowedDevOrigins: ["100.64.0.10"],
+ images: {
+ remotePatterns: [
+ {
+ protocol: "https",
+ hostname: "supabase.pascalyazid.com",
+ port: "",
+ pathname: "/storage/v1/object/sign/avatars/**",
+ },
+ ],
+ },
};
export default nextConfig;
diff --git a/package.json b/package.json
index 122556b..9c3d79d 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"dependencies": {
"@supabase/ssr": "^0.10.3",
"next": "16.2.6",
+ "qrcode.react": "^4.2.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
diff --git a/proxy.ts b/proxy.ts
new file mode 100644
index 0000000..5e840cb
--- /dev/null
+++ b/proxy.ts
@@ -0,0 +1,19 @@
+import { type NextRequest } from "next/server";
+import { updateSession } from "@/utils/supabase/middleware";
+
+export async function proxy(request: NextRequest) {
+ return await updateSession(request);
+}
+
+export const config = {
+ matcher: [
+ /*
+ * Match all request paths except:
+ * - _next/static (static files)
+ * - _next/image (image optimization files)
+ * - favicon.ico (favicon file)
+ * - public files (svg, png, jpg, etc.)
+ */
+ "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
+ ],
+};
diff --git a/types/chat.ts b/types/chat.ts
index 4cefdae..5cb1d5d 100644
--- a/types/chat.ts
+++ b/types/chat.ts
@@ -12,5 +12,6 @@ export interface Message {
room_id: string;
user: {
name: string;
- };
+ avatar_url: string | null;
+ } | null;
}
diff --git a/types/profile.ts b/types/profile.ts
index 0b29f19..1885de3 100644
--- a/types/profile.ts
+++ b/types/profile.ts
@@ -2,6 +2,12 @@ export interface Profile {
id: string;
email: string;
name: string;
- avatar_url: string;
- createdAt: string;
+ avatar_url: string | null;
+ created_at: string;
+ has_identity: boolean;
+ private_key_enc: string | null;
+ public_key_dec: string | null;
+ salt: string | null;
+ iv: string | null;
+ auth_tag: string | null;
}
diff --git a/utils/assets/avatars.ts b/utils/assets/avatars.ts
new file mode 100644
index 0000000..f013b72
--- /dev/null
+++ b/utils/assets/avatars.ts
@@ -0,0 +1,75 @@
+"use server";
+
+import { createClient } from "@/utils/supabase/server";
+
+/**
+ * Generate a signed URL for a user's avatar from Supabase storage.
+ * The bucket is private, so signed URLs are required to access avatars.
+ *
+ * @param userId - The user ID whose avatar to fetch
+ * @param expiresIn - URL expiry in seconds (default: 1 hour)
+ * @returns Signed URL string, or null if not found/error
+ */
+export async function getSignedAvatarUrl(
+ userId: string,
+ expiresIn: number = 3600,
+): Promise {
+ const supabase = await createClient();
+ const { data, error } = await supabase.storage
+ .from("avatars")
+ .createSignedUrl(`${userId}/avatar`, expiresIn);
+
+ if (error || !data?.signedUrl) {
+ return null;
+ }
+
+ return data.signedUrl;
+}
+
+/**
+ * Generate signed avatar URLs for multiple users at once.
+ * Returns a Map of userId -> signedUrl (null if no avatar).
+ *
+ * @param userIds - Array of user IDs
+ * @param expiresIn - URL expiry in seconds (default: 1 hour)
+ */
+export async function getSignedAvatarUrls(
+ userIds: string[],
+ expiresIn: number = 3600,
+): Promise