From dad88f88e3c5ae70768fe03bf328fc0538c457d8 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Thu, 4 Jun 2026 11:37:01 -0400 Subject: [PATCH] feat: all of auth, start of settings --- app/{ => (app)}/[...not-found]/page.tsx | 0 app/{ => (app)}/album/[id]/loading.tsx | 0 app/{ => (app)}/album/[id]/page.tsx | 0 app/{ => (app)}/artist/[id]/loading.tsx | 0 app/{ => (app)}/artist/[id]/page.tsx | 0 app/(app)/layout.tsx | 17 + app/{ => (app)}/library/albums/page.tsx | 0 app/{ => (app)}/library/artists/page.tsx | 0 app/{ => (app)}/library/songs/page.tsx | 0 app/{ => (app)}/page.tsx | 0 app/{ => (app)}/recently-added/page.tsx | 0 app/{ => (app)}/recently-played/page.tsx | 0 app/{ => (app)}/search/page.tsx | 0 app/(auth)/layout.tsx | 11 + app/(auth)/signin/page.tsx | 7 + app/(auth)/signup/page.tsx | 7 + app/layout.tsx | 24 +- components/app-sidebar.tsx | 86 ++- components/auth-form.tsx | 164 +++++ components/convex-client-provider.tsx | 16 +- components/options-modal.tsx | 855 +++++++++++++++++++++++ components/player-bar.tsx | 2 +- components/ui/dropdown-menu.tsx | 6 +- convex/_generated/api.d.ts | 6 + convex/auth.config.ts | 8 + convex/auth.ts | 61 ++ convex/http.ts | 8 + convex/schema.ts | 20 + convex/users.ts | 325 +++++++++ lib/resize-profile-image.ts | 49 ++ package-lock.json | 227 +++++- package.json | 2 + proxy.ts | 23 + 33 files changed, 1876 insertions(+), 48 deletions(-) rename app/{ => (app)}/[...not-found]/page.tsx (100%) rename app/{ => (app)}/album/[id]/loading.tsx (100%) rename app/{ => (app)}/album/[id]/page.tsx (100%) rename app/{ => (app)}/artist/[id]/loading.tsx (100%) rename app/{ => (app)}/artist/[id]/page.tsx (100%) create mode 100644 app/(app)/layout.tsx rename app/{ => (app)}/library/albums/page.tsx (100%) rename app/{ => (app)}/library/artists/page.tsx (100%) rename app/{ => (app)}/library/songs/page.tsx (100%) rename app/{ => (app)}/page.tsx (100%) rename app/{ => (app)}/recently-added/page.tsx (100%) rename app/{ => (app)}/recently-played/page.tsx (100%) rename app/{ => (app)}/search/page.tsx (100%) create mode 100644 app/(auth)/layout.tsx create mode 100644 app/(auth)/signin/page.tsx create mode 100644 app/(auth)/signup/page.tsx create mode 100644 components/auth-form.tsx create mode 100644 components/options-modal.tsx create mode 100644 convex/auth.config.ts create mode 100644 convex/auth.ts create mode 100644 convex/http.ts create mode 100644 convex/users.ts create mode 100644 lib/resize-profile-image.ts create mode 100644 proxy.ts diff --git a/app/[...not-found]/page.tsx b/app/(app)/[...not-found]/page.tsx similarity index 100% rename from app/[...not-found]/page.tsx rename to app/(app)/[...not-found]/page.tsx diff --git a/app/album/[id]/loading.tsx b/app/(app)/album/[id]/loading.tsx similarity index 100% rename from app/album/[id]/loading.tsx rename to app/(app)/album/[id]/loading.tsx diff --git a/app/album/[id]/page.tsx b/app/(app)/album/[id]/page.tsx similarity index 100% rename from app/album/[id]/page.tsx rename to app/(app)/album/[id]/page.tsx diff --git a/app/artist/[id]/loading.tsx b/app/(app)/artist/[id]/loading.tsx similarity index 100% rename from app/artist/[id]/loading.tsx rename to app/(app)/artist/[id]/loading.tsx diff --git a/app/artist/[id]/page.tsx b/app/(app)/artist/[id]/page.tsx similarity index 100% rename from app/artist/[id]/page.tsx rename to app/(app)/artist/[id]/page.tsx diff --git a/app/(app)/layout.tsx b/app/(app)/layout.tsx new file mode 100644 index 0000000..045663d --- /dev/null +++ b/app/(app)/layout.tsx @@ -0,0 +1,17 @@ +import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar" +import { AppSidebar } from "@/components/app-sidebar" +import { PlayerBar } from "@/components/player-bar" + +export default function AppLayout({ + children, +}: Readonly<{ + children: React.ReactNode +}>) { + return ( + + + {children} + + + ) +} diff --git a/app/library/albums/page.tsx b/app/(app)/library/albums/page.tsx similarity index 100% rename from app/library/albums/page.tsx rename to app/(app)/library/albums/page.tsx diff --git a/app/library/artists/page.tsx b/app/(app)/library/artists/page.tsx similarity index 100% rename from app/library/artists/page.tsx rename to app/(app)/library/artists/page.tsx diff --git a/app/library/songs/page.tsx b/app/(app)/library/songs/page.tsx similarity index 100% rename from app/library/songs/page.tsx rename to app/(app)/library/songs/page.tsx diff --git a/app/page.tsx b/app/(app)/page.tsx similarity index 100% rename from app/page.tsx rename to app/(app)/page.tsx diff --git a/app/recently-added/page.tsx b/app/(app)/recently-added/page.tsx similarity index 100% rename from app/recently-added/page.tsx rename to app/(app)/recently-added/page.tsx diff --git a/app/recently-played/page.tsx b/app/(app)/recently-played/page.tsx similarity index 100% rename from app/recently-played/page.tsx rename to app/(app)/recently-played/page.tsx diff --git a/app/search/page.tsx b/app/(app)/search/page.tsx similarity index 100% rename from app/search/page.tsx rename to app/(app)/search/page.tsx diff --git a/app/(auth)/layout.tsx b/app/(auth)/layout.tsx new file mode 100644 index 0000000..9dd93a3 --- /dev/null +++ b/app/(auth)/layout.tsx @@ -0,0 +1,11 @@ +export default function AuthLayout({ + children, +}: Readonly<{ + children: React.ReactNode +}>) { + return ( +
+ {children} +
+ ) +} diff --git a/app/(auth)/signin/page.tsx b/app/(auth)/signin/page.tsx new file mode 100644 index 0000000..bfe85ce --- /dev/null +++ b/app/(auth)/signin/page.tsx @@ -0,0 +1,7 @@ +"use client" + +import { AuthForm } from "@/components/auth-form" + +export default function SignInPage() { + return +} diff --git a/app/(auth)/signup/page.tsx b/app/(auth)/signup/page.tsx new file mode 100644 index 0000000..8169ec4 --- /dev/null +++ b/app/(auth)/signup/page.tsx @@ -0,0 +1,7 @@ +"use client" + +import { AuthForm } from "@/components/auth-form" + +export default function SignUpPage() { + return +} diff --git a/app/layout.tsx b/app/layout.tsx index c867ec3..4453162 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,12 +1,10 @@ import { Geist, Geist_Mono, Inter } from "next/font/google" import "./globals.css" +import { ConvexAuthNextjsServerProvider } from "@convex-dev/auth/nextjs/server" import { ConvexClientProvider } from "@/components/convex-client-provider" import { ThemeProvider } from "@/components/theme-provider" import { cn } from "@/lib/utils" -import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar" -import { AppSidebar } from "@/components/app-sidebar" -import { PlayerBar } from "@/components/player-bar" import { Toaster } from "@/components/ui/sonner" import type { Metadata } from "next" @@ -39,18 +37,14 @@ export default function RootLayout({ )} > - - - - - - {children} - - - - - - + + + + {children} + + + + ) diff --git a/components/app-sidebar.tsx b/components/app-sidebar.tsx index 2b6a19d..73c246d 100644 --- a/components/app-sidebar.tsx +++ b/components/app-sidebar.tsx @@ -5,15 +5,25 @@ import { House, LayoutGrid, ListMusic, + LogOut, Mic, Music2, Search, + Settings, Star, } from "lucide-react" -import { usePathname } from "next/navigation" +import { usePathname, useRouter } from "next/navigation" +import { useAuthActions } from "@convex-dev/auth/react" -import { Avatar, AvatarFallback } from "@/components/ui/avatar" +import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { OptionsModal } from "@/components/options-modal" import { Sidebar, SidebarContent, @@ -32,6 +42,8 @@ import Link from "next/link" import { useTheme } from "next-themes" import * as React from "react" import { placeholderPlaylists } from "@/lib/playlists" +import { useQuery } from "convex/react" +import { api } from "@/convex/_generated/api" const browse = [ { title: "Home", path: "/", icon: House }, @@ -56,9 +68,19 @@ const playlists = [ export function AppSidebar() { const pathname = usePathname() + const router = useRouter() + const { signOut } = useAuthActions() + const user = useQuery(api.auth.currentUser) + const fallbackLetters = user?.name?.match(/\b(\w)/g)!.join('') || "NA" const { resolvedTheme } = useTheme() const [mounted, setMounted] = React.useState(false) + const [optionsOpen, setOptionsOpen] = React.useState(false) + + async function handleSignOut() { + await signOut() + router.push("/signin") + } React.useEffect(() => { setMounted(true) @@ -70,7 +92,13 @@ export function AppSidebar() {
- {"oTunes"} + {"oTunes"} oTunes
@@ -81,10 +109,7 @@ export function AppSidebar() { {browse.map((item) => ( - + {item.title} @@ -102,10 +127,7 @@ export function AppSidebar() { {library.map((item) => ( - + {item.title} @@ -123,10 +145,7 @@ export function AppSidebar() { {playlists.map((item) => ( - + {item.title} @@ -142,12 +161,37 @@ export function AppSidebar() { - - - JH - - Joshua Higgins - + + + + + {user?.image ? ( + + ) : null} + {fallbackLetters} + + {user?.name || "N/A"} + + + + + Sign Out + + + setOptionsOpen(true)} + > + Options + + + + + diff --git a/components/auth-form.tsx b/components/auth-form.tsx new file mode 100644 index 0000000..7f97d72 --- /dev/null +++ b/components/auth-form.tsx @@ -0,0 +1,164 @@ +"use client" + +import { useState } from "react" +import { useRouter } from "next/navigation" +import Link from "next/link" +import { useAuthActions } from "@convex-dev/auth/react" +import { useQuery } from "convex/react" + +import { Button } from "@/components/ui/button" +import { api } from "@/convex/_generated/api" +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card" +import { Field, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field" +import { Input } from "@/components/ui/input" +import { Spinner } from "@/components/ui/spinner" + +type AuthFlow = "signIn" | "signUp" + +const copy: Record< + AuthFlow, + { + title: string + description: string + submit: string + switchPrompt: string + switchLabel: string + switchHref: string + } +> = { + signIn: { + title: "Welcome back", + description: "Sign in to your oTunes account to keep listening.", + submit: "Sign in", + switchPrompt: "Don't have an account?", + switchLabel: "Sign up", + switchHref: "/signup", + }, + signUp: { + title: "Create your account", + description: "Sign up to start building your oTunes library.", + submit: "Sign up", + switchPrompt: "Already have an account?", + switchLabel: "Sign in", + switchHref: "/signin", + }, +} + +export function AuthForm({ flow }: { flow: AuthFlow }) { + const { signIn } = useAuthActions() + const router = useRouter() + const appSettings = useQuery(api.users.getAppSettings) + const [error, setError] = useState(null) + const [submitting, setSubmitting] = useState(false) + + const text = copy[flow] + const accountCreationDisabled = appSettings?.disableAccountCreation ?? false + const signupsDisabled = flow === "signUp" && accountCreationDisabled + const hideSignUpLink = flow === "signIn" && accountCreationDisabled + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault() + if (signupsDisabled) { + return + } + setError(null) + setSubmitting(true) + + const formData = new FormData(event.currentTarget) + formData.set("flow", flow) + + try { + await signIn("password", formData) + router.push("/") + } catch { + setError( + flow === "signIn" + ? "Invalid email or password." + : "Could not create account. Try a different email." + ) + setSubmitting(false) + } + } + + return ( + + + {text.title} + {text.description} + + + {signupsDisabled ? ( +

+ New account registration is currently disabled. Contact an + administrator if you need access. +

+ ) : ( +
+ + {flow === "signUp" && ( + + Name + + + )} + + Email + + + + Password + + + {error && {error}} + + + + {!hideSignUpLink ? ( +

+ {text.switchPrompt}{" "} + + {text.switchLabel} + +

+ ) : null} +
+
+ )} +
+
+ ) +} diff --git a/components/convex-client-provider.tsx b/components/convex-client-provider.tsx index 31c2fa5..8434781 100644 --- a/components/convex-client-provider.tsx +++ b/components/convex-client-provider.tsx @@ -1,13 +1,15 @@ "use client" -import { ConvexProvider, ConvexReactClient } from "convex/react" +import { ConvexAuthNextjsProvider } from "@convex-dev/auth/nextjs" +import { ConvexReactClient } from "convex/react" +import { ReactNode } from "react" const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!) -export function ConvexClientProvider({ - children, -}: { - children: React.ReactNode -}) { - return {children} +export function ConvexClientProvider({ children }: { children: ReactNode }) { + return ( + + {children} + + ) } diff --git a/components/options-modal.tsx b/components/options-modal.tsx new file mode 100644 index 0000000..0d83af8 --- /dev/null +++ b/components/options-modal.tsx @@ -0,0 +1,855 @@ +"use client" + +import { useAction, useMutation, useQuery } from "convex/react" +import { + MoreHorizontal, + Trash2, + Upload, + UserPlus, +} from "lucide-react" +import { useCallback, useEffect, useRef, useState } from "react" +import { toast } from "sonner" + +import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" +import { Button } from "@/components/ui/button" +import { Checkbox } from "@/components/ui/checkbox" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { Field, FieldGroup, FieldLabel } from "@/components/ui/field" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" +import { ScrollArea } from "@/components/ui/scroll-area" +import { Separator } from "@/components/ui/separator" +import { Spinner } from "@/components/ui/spinner" +import { Switch } from "@/components/ui/switch" +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table" +import { api } from "@/convex/_generated/api" +import type { Doc, Id } from "@/convex/_generated/dataModel" +import { resizeProfileImageToDataUrl } from "@/lib/resize-profile-image" +import { cn } from "@/lib/utils" + +type Section = "profile" | "quality" | "users" + +type PlaybackQuality = "low" | "medium" | "high" | "lossless" + +const QUALITY_OPTIONS: { + value: PlaybackQuality + label: string + description: string +}[] = [ + { value: "low", label: "Low", description: "AAC HE 128kb/s" }, + { value: "medium", label: "Medium", description: "AAC 256kb/s" }, + { value: "high", label: "High", description: "AAC 320kb/s" }, + { value: "lossless", label: "Lossless", description: "ALAC" }, +] + +function useDebouncedCallback void>( + callback: T, + delay: number +) { + const timeoutRef = useRef | null>(null) + const callbackRef = useRef(callback) + callbackRef.current = callback + + useEffect(() => { + return () => { + if (timeoutRef.current) clearTimeout(timeoutRef.current) + } + }, []) + + return useCallback( + (...args: Parameters) => { + if (timeoutRef.current) clearTimeout(timeoutRef.current) + timeoutRef.current = setTimeout(() => { + callbackRef.current(...args) + }, delay) + }, + [delay] + ) +} + +function NavButton({ + active, + onClick, + children, +}: { + active: boolean + onClick: () => void + children: React.ReactNode +}) { + return ( + + ) +} + +function UserAvatar({ + user, + size = "default", +}: { + user: Pick, "name" | "image"> + size?: "default" | "sm" +}) { + const initials = user.name + .split(" ") + .map((part) => part[0]) + .join("") + .slice(0, 2) + .toUpperCase() + + return ( + + {user.image ? ( + + ) : null} + {initials} + + ) +} + +function ProfileSection({ user }: { user: Doc<"users"> }) { + const updateName = useMutation(api.users.updateProfileName) + const updateEmail = useMutation(api.users.updateProfileEmail) + const updateImage = useMutation(api.users.updateProfileImage) + const updatePassword = useAction(api.users.updateOwnPassword) + + const [name, setName] = useState(user.name) + const [email, setEmail] = useState(user.email) + const [newPassword, setNewPassword] = useState("") + const [confirmPassword, setConfirmPassword] = useState("") + const [changingPassword, setChangingPassword] = useState(false) + const fileInputRef = useRef(null) + + useEffect(() => { + setName(user.name) + setEmail(user.email) + }, [user.name, user.email]) + + const debouncedUpdateName = useDebouncedCallback((value: string) => { + if (value.trim() === user.name) return + updateName({ name: value }).catch((error: Error) => + toast.error(error.message) + ) + }, 500) + + const debouncedUpdateEmail = useDebouncedCallback((value: string) => { + if (value.trim().toLowerCase() === user.email) return + updateEmail({ email: value }).catch((error: Error) => + toast.error(error.message) + ) + }, 500) + + async function handleImageUpload(file: File) { + if (!file.type.startsWith("image/")) { + toast.error("Please upload an image file") + return + } + if (file.size > 2 * 1024 * 1024) { + toast.error("Image must be smaller than 2 MB") + return + } + + try { + const dataUrl = await resizeProfileImageToDataUrl(file) + await updateImage({ image: dataUrl }) + toast.success("Profile photo updated") + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Failed to update photo" + ) + } + } + + async function handleClearImage() { + try { + await updateImage({}) + toast.success("Profile photo removed") + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Failed to remove photo" + ) + } + } + + async function handlePasswordChange() { + if (newPassword !== confirmPassword) { + toast.error("Passwords do not match") + return + } + if (newPassword.length < 8) { + toast.error("Password must be at least 8 characters") + return + } + + setChangingPassword(true) + try { + await updatePassword({ newPassword }) + setNewPassword("") + setConfirmPassword("") + toast.success("Password updated") + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Failed to update password" + ) + } finally { + setChangingPassword(false) + } + } + + return ( +
+
+

Profile

+

+ Manage your profile photo and account details. +

+
+ + + + Profile photo +
+ +
+ { + const file = event.target.files?.[0] + if (file) void handleImageUpload(file) + event.target.value = "" + }} + /> + + {user.image ? ( + + ) : null} +
+
+
+ + + Name + { + setName(event.target.value) + debouncedUpdateName(event.target.value) + }} + /> + + + + Email + { + setEmail(event.target.value) + debouncedUpdateEmail(event.target.value) + }} + /> + +
+ + + +
+
+

Password

+

+ Confirm your new password to update it. +

+
+ + + New password + setNewPassword(event.target.value)} + /> + + + Confirm password + setConfirmPassword(event.target.value)} + /> + + + + + +
+
+ ) +} + +function QualitySection({ user }: { user: Doc<"users"> }) { + const updateQuality = useMutation(api.users.updatePlaybackQuality) + const updateAtmos = useMutation(api.users.updatePreferAtmos) + + const quality = user.playbackQuality ?? "medium" + + return ( +
+
+

Quality

+

+ Choose your preferred playback quality and spatial audio options. +

+
+ + { + updateQuality({ playbackQuality: value as PlaybackQuality }).catch( + (error: Error) => toast.error(error.message) + ) + }} + className="gap-3" + > + {QUALITY_OPTIONS.map((option) => ( +
+ + +
+ ))} +
+ +
+ { + updateAtmos({ preferAtmos: checked === true }).catch( + (error: Error) => toast.error(error.message) + ) + }} + /> + +
+
+ ) +} + +function CreateUserDialog({ + open, + onOpenChange, +}: { + open: boolean + onOpenChange: (open: boolean) => void +}) { + const createUser = useAction(api.users.adminCreateUser) + const [name, setName] = useState("") + const [email, setEmail] = useState("") + const [password, setPassword] = useState("") + const [isAdmin, setIsAdmin] = useState(false) + const [submitting, setSubmitting] = useState(false) + + function reset() { + setName("") + setEmail("") + setPassword("") + setIsAdmin(false) + } + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault() + setSubmitting(true) + try { + await createUser({ name, email, password, isAdmin }) + toast.success("User created") + reset() + onOpenChange(false) + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Failed to create user" + ) + } finally { + setSubmitting(false) + } + } + + return ( + + + + Create user + + Add a new account with email and password. + + +
void handleSubmit(event)}> + + + Name + setName(event.target.value)} + required + /> + + + Email + setEmail(event.target.value)} + required + /> + + + Password + setPassword(event.target.value)} + required + minLength={8} + /> + +
+ setIsAdmin(checked === true)} + /> + +
+
+ + + +
+
+
+ ) +} + +function ChangePasswordDialog({ + user, + open, + onOpenChange, +}: { + user: Doc<"users"> + open: boolean + onOpenChange: (open: boolean) => void +}) { + const changePassword = useAction(api.users.adminChangeUserPassword) + const [password, setPassword] = useState("") + const [confirm, setConfirm] = useState("") + const [submitting, setSubmitting] = useState(false) + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault() + if (password !== confirm) { + toast.error("Passwords do not match") + return + } + setSubmitting(true) + try { + await changePassword({ userId: user._id, newPassword: password }) + toast.success(`Password updated for ${user.name}`) + setPassword("") + setConfirm("") + onOpenChange(false) + } catch (error) { + toast.error( + error instanceof Error ? error.message : "Failed to update password" + ) + } finally { + setSubmitting(false) + } + } + + return ( + + + + Change password + + Set a new password for {user.name} ({user.email}). + + +
void handleSubmit(event)}> + + + New password + setPassword(event.target.value)} + required + minLength={8} + /> + + + + Confirm password + + setConfirm(event.target.value)} + required + minLength={8} + /> + + + + + +
+
+
+ ) +} + +function UserRowActions({ + user, + currentUserId, +}: { + user: Doc<"users"> + currentUserId: Id<"users"> +}) { + const setAdmin = useMutation(api.users.setUserAdmin) + const deleteUserMutation = useMutation(api.users.deleteUser) + const [passwordDialogOpen, setPasswordDialogOpen] = useState(false) + const [deleting, setDeleting] = useState(false) + + const isSelf = user._id === currentUserId + + return ( + <> + + + + + + {!isSelf && ( + { + setAdmin({ userId: user._id, isAdmin: !user.isAdmin }) + .then(() => + toast.success( + user.isAdmin ? "Admin access removed" : "User is now admin" + ) + ) + .catch((error: Error) => toast.error(error.message)) + }} + > + {user.isAdmin ? "Remove admin" : "Make admin"} + + )} + setPasswordDialogOpen(true)}> + Change password + + {!isSelf && ( + <> + + { + setDeleting(true) + deleteUserMutation({ userId: user._id }) + .then(() => toast.success("User deleted")) + .catch((error: Error) => toast.error(error.message)) + .finally(() => setDeleting(false)) + }} + > + + Delete account + + + )} + + + + + ) +} + +function UsersSection({ + users, + currentUserId, +}: { + users: Doc<"users">[] + currentUserId: Id<"users"> +}) { + const appSettings = useQuery(api.users.getAppSettings) + const setDisableCreation = useMutation(api.users.setDisableAccountCreation) + const [createOpen, setCreateOpen] = useState(false) + + return ( +
+
+

Users

+

+ Manage accounts, permissions, and sign-up settings. +

+
+ +
+
+ { + setDisableCreation({ disabled: checked }) + .then(() => + toast.success( + checked + ? "Account creation disabled" + : "Account creation enabled" + ) + ) + .catch((error: Error) => toast.error(error.message)) + }} + /> + +
+ +
+ + + + + User + Name + Email + + + + + {users.map((user) => ( + + +
+ + {user.isAdmin ? ( + Admin + ) : null} +
+
+ {user.name} + {user.email} + + + +
+ ))} +
+
+ + +
+ ) +} + +export function OptionsModal({ + open, + onOpenChange, +}: { + open: boolean + onOpenChange: (open: boolean) => void +}) { + const user = useQuery(api.auth.currentUser) + const allUsers = useQuery(api.users.listUsers) + const [section, setSection] = useState
("profile") + + const isAdmin = user?.isAdmin === true + + useEffect(() => { + if (!open) { + setSection("profile") + } + }, [open]) + + useEffect(() => { + if (!isAdmin && section === "users") { + setSection("profile") + } + }, [isAdmin, section]) + + if (!user) { + return null + } + + return ( + + + Settings +
+ + + +
+ {section === "profile" && } + {section === "quality" && } + {section === "users" && isAdmin && allUsers ? ( + + ) : null} +
+
+
+
+
+ ) +} diff --git a/components/player-bar.tsx b/components/player-bar.tsx index 2ba6a1b..c72c3c7 100644 --- a/components/player-bar.tsx +++ b/components/player-bar.tsx @@ -15,7 +15,7 @@ import { Button } from "@/components/ui/button" export function PlayerBar() { return ( -
+