diff --git a/apps/mobile/app.json b/apps/mobile/app.json
index d635004..54025c2 100644
--- a/apps/mobile/app.json
+++ b/apps/mobile/app.json
@@ -44,24 +44,7 @@
[
"expo-splash-screen",
{
- "ios": {
- "backgroundColor": "#ffffff",
- "image": "./assets/ios-icon.png",
- "dark": {
- "image": "./assets/ios-icon-dark.png",
- "backgroundColor": "#000000"
- },
- "imageWidth": 200
- },
- "android": {
- "backgroundColor": "#ffffff",
- "image": "./assets/icon.png",
- "dark": {
- "image": "./assets/icon-dark.png",
- "backgroundColor": "#000000"
- },
- "imageWidth": 200
- }
+ "backgroundColor": "#000000"
}
],
"expo-image",
diff --git a/apps/mobile/app/(app)/(tabs)/_layout.tsx b/apps/mobile/app/(app)/(tabs)/_layout.tsx
index 70dc1ac..352876f 100644
--- a/apps/mobile/app/(app)/(tabs)/_layout.tsx
+++ b/apps/mobile/app/(app)/(tabs)/_layout.tsx
@@ -7,6 +7,8 @@ import { TabBottomAccessory } from "@/components/mini-player"
import { usePlaybackQueue } from "@/contexts/playback"
import { appleMusic, colors } from "@/lib/theme"
+export const unstable_settings = { anchor: "library" }
+
function useRouterTheme() {
const isDark = useColorScheme() === "dark"
diff --git a/apps/mobile/app/(app)/(tabs)/home/settings.tsx b/apps/mobile/app/(app)/(tabs)/home/settings.tsx
index 80e6a13..fd46e48 100644
--- a/apps/mobile/app/(app)/(tabs)/home/settings.tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/settings.tsx
@@ -2,7 +2,6 @@ import { Ionicons } from "@expo/vector-icons"
import { useAction, useMutation, useQuery } from "convex/react"
import { Image } from "expo-image"
import * as ImagePicker from "expo-image-picker"
-import { useRouter } from "expo-router"
import { useState } from "react"
import {
Pressable,
@@ -20,7 +19,7 @@ import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
import { useServerConfig } from "@/contexts/server-config"
import { initialsFromName } from "@/lib/format"
import { useCachedQuery } from "@/hooks/use-cached-query"
-import { clearLocalData, signOutToSignIn } from "@/lib/session"
+import { changeServer, signOut } from "@/lib/session"
import { radius, spacing, useThemeColors } from "@/lib/theme"
import { showError } from "@/lib/toast"
import type { PlaybackQuality } from "@/lib/urls"
@@ -73,7 +72,6 @@ const SECTIONS: SectionConfig[] = [
export default function SettingsScreen() {
const colors = useThemeColors()
- const router = useRouter()
const user = useCachedQuery(api.auth.currentUser)
const { invalidateSession } = useInvalidateAuthSession()
const { clearServer } = useServerConfig()
@@ -91,14 +89,19 @@ export default function SettingsScreen() {
const visibleSections = SECTIONS.filter((item) => !item.admin || isAdmin)
async function handleSignOut() {
- await signOutToSignIn(router, invalidateSession)
+ try {
+ await signOut(invalidateSession)
+ } catch {
+ showError("Could not clear all local data.")
+ }
}
async function handleChangeServer() {
- await invalidateSession()
- await clearLocalData()
- await clearServer()
- router.replace("/server")
+ try {
+ await changeServer(invalidateSession, clearServer)
+ } catch {
+ showError("Could not clear all local data.")
+ }
}
return (
diff --git a/apps/mobile/app/(app)/(tabs)/library/index.tsx b/apps/mobile/app/(app)/(tabs)/library/index.tsx
index d5382c6..44eff2e 100644
--- a/apps/mobile/app/(app)/(tabs)/library/index.tsx
+++ b/apps/mobile/app/(app)/(tabs)/library/index.tsx
@@ -61,12 +61,14 @@ export default function LibraryScreen() {
{links.map((link) => (
push(link.href)}
>
- {link.title}
-
+
+ {link.title}
+
+
))}
@@ -111,6 +113,12 @@ const styles = StyleSheet.create({
alignItems: "center",
gap: spacing.md,
paddingHorizontal: spacing.lg,
+ },
+ rowContent: {
+ flex: 1,
+ flexDirection: "row",
+ alignItems: "center",
+ gap: spacing.md,
paddingVertical: 14,
borderBottomWidth: StyleSheet.hairlineWidth,
},
diff --git a/apps/mobile/app/(app)/_layout.tsx b/apps/mobile/app/(app)/_layout.tsx
index 1823612..186accd 100644
--- a/apps/mobile/app/(app)/_layout.tsx
+++ b/apps/mobile/app/(app)/_layout.tsx
@@ -3,25 +3,22 @@ import {
useConvexAuth as useServerConvexAuth,
useConvexConnectionState,
} from "convex/react"
-import { Redirect, Stack } from "expo-router"
+import { Stack } from "expo-router"
import { Platform } from "react-native"
import { useEffect } from "react"
import { AppIntentBridge } from "@/components/app-intent-bridge"
import { ConvexAuthRecovery } from "@/components/convex-auth-recovery"
-import { LoadingView } from "@/components/ui/primitives"
import { AddToPlaylistProvider } from "@/contexts/add-to-playlist"
import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
import { FavoritesProvider } from "@/contexts/favorites"
import { PlaybackProvider } from "@/contexts/playback"
-import { useServerConfig } from "@/contexts/server-config"
import { useStackScreenOptions } from "@/lib/navigation"
import { AppNavigationSync } from "@/lib/app-navigation"
const AUTH_HANDSHAKE_TIMEOUT_MS = 15_000
export default function AppLayout() {
- const { config } = useServerConfig()
const localAuth = useLocalConvexAuth()
const serverAuth = useServerConvexAuth()
const { isWebSocketConnected } = useConvexConnectionState()
@@ -51,18 +48,6 @@ export default function AppLayout() {
serverAuth?.isAuthenticated,
])
- if (!config) {
- return
- }
-
- if (!localAuth || localAuth.isLoading) {
- return
- }
-
- if (!localAuth.isAuthenticated) {
- return
- }
-
// Convex holds queries until the stored token is confirmed, so the app can
// render cached data while the server handshake is still in progress.
@@ -74,7 +59,10 @@ export default function AppLayout() {
-
+
-}
diff --git a/apps/mobile/app/(auth)/_layout.tsx b/apps/mobile/app/(auth)/_layout.tsx
index a2bf828..8e74597 100644
--- a/apps/mobile/app/(auth)/_layout.tsx
+++ b/apps/mobile/app/(auth)/_layout.tsx
@@ -1,28 +1,7 @@
-import { useConvexAuth } from "@convex-dev/auth/react"
-import { Redirect, Stack } from "expo-router"
+import { Stack } from "expo-router"
-import { LoadingView } from "@/components/ui/primitives"
-import { useServerConfig } from "@/contexts/server-config"
+export const unstable_settings = { anchor: "signin" }
export default function AuthLayout() {
- const { config, isLoading: serverLoading } = useServerConfig()
- const auth = useConvexAuth()
-
- if (serverLoading) {
- return
- }
-
- if (!config) {
- return
- }
-
- if (!auth || auth.isLoading) {
- return
- }
-
- if (auth.isAuthenticated) {
- return
- }
-
return
}
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx
index 71877dc..51c5f71 100644
--- a/apps/mobile/app/_layout.tsx
+++ b/apps/mobile/app/_layout.tsx
@@ -1,4 +1,5 @@
-import { Stack } from "expo-router"
+import { useConvexAuth } from "@convex-dev/auth/react"
+import { DarkTheme, Stack, ThemeProvider } from "expo-router"
import { StatusBar } from "expo-status-bar"
import { useColorScheme } from "react-native"
import { GestureHandlerRootView } from "react-native-gesture-handler"
@@ -6,23 +7,57 @@ import { SafeAreaProvider } from "react-native-safe-area-context"
import { Toaster } from "@/components/ui/toaster"
import { ConvexAppProvider } from "@/contexts/convex-app"
-import { ServerConfigProvider } from "@/contexts/server-config"
+import { ServerConfigProvider, useServerConfig } from "@/contexts/server-config"
+
+const navigationTheme = {
+ ...DarkTheme,
+ colors: { ...DarkTheme.colors, background: "#000", card: "#000" },
+}
+
+function RootNavigator() {
+ const { config, isLoading } = useServerConfig()
+ const auth = useConvexAuth()
+
+ if (isLoading || (config && (!auth || auth.isLoading))) {
+ return null
+ }
+
+ const isAuthenticated = Boolean(config && auth?.isAuthenticated)
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
export default function RootLayout() {
const colorScheme = useColorScheme()
return (
-
+
-
-
-
-
-
-
+
+
+
diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsx
index c15052a..0a2502f 100644
--- a/apps/mobile/app/index.tsx
+++ b/apps/mobile/app/index.tsx
@@ -1,19 +1,19 @@
+import { useConvexAuth } from "@convex-dev/auth/react"
import { Redirect } from "expo-router"
-import { LoadingView } from "@/components/ui/primitives"
import { useServerConfig } from "@/contexts/server-config"
-import { AuthenticatedRedirect } from "@/components/authenticated-redirect"
export default function Index() {
- const { config, isLoading } = useServerConfig()
-
- if (isLoading) {
- return
- }
+ const { config } = useServerConfig()
+ const auth = useConvexAuth()
if (!config) {
return
}
- return
+ return (
+
+ )
}
diff --git a/apps/mobile/app/server.tsx b/apps/mobile/app/server.tsx
index 9eb89c3..036c79b 100644
--- a/apps/mobile/app/server.tsx
+++ b/apps/mobile/app/server.tsx
@@ -1,5 +1,4 @@
-import { useRouter } from "expo-router"
-import { useEffect, useState } from "react"
+import { useState } from "react"
import {
KeyboardAvoidingView,
Platform,
@@ -14,19 +13,12 @@ import { useServerConfig } from "@/contexts/server-config"
import { spacing, useThemeColors } from "@/lib/theme"
export default function ServerScreen() {
- const router = useRouter()
const colors = useThemeColors()
- const { config, isLoading, setServerHostname } = useServerConfig()
+ const { setServerHostname } = useServerConfig()
const [hostname, setHostname] = useState("")
const [error, setError] = useState(null)
const [submitting, setSubmitting] = useState(false)
- useEffect(() => {
- if (config?.hostname) {
- setHostname(config.hostname)
- }
- }, [config?.hostname])
-
async function handleContinue() {
setError(null)
setSubmitting(true)
@@ -38,7 +30,6 @@ export default function ServerScreen() {
)
return
}
- router.replace("/signin")
} catch {
setError(
"Could not save the server address. Check device storage and try again."
@@ -48,10 +39,6 @@ export default function ServerScreen() {
}
}
- if (isLoading) {
- return null
- }
-
return (
(null)
const [submitting, setSubmitting] = useState(false)
- useEffect(() => {
- if (auth.isAuthenticated) {
- router.replace("/(app)/(tabs)/home")
- }
- }, [auth.isAuthenticated, router])
-
const text = copy[flow]
const accountCreationDisabled = appSettings?.disableAccountCreation ?? false
const signupsDisabled = flow === "signUp" && accountCreationDisabled
@@ -164,11 +157,16 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
)}
-
-
- Change server
-
-
+
+ void clearServer().catch(() =>
+ showError("Could not clear the server address.")
+ )
+ }
+ >
+ Change server
+
)
diff --git a/apps/mobile/components/authenticated-redirect.tsx b/apps/mobile/components/authenticated-redirect.tsx
deleted file mode 100644
index 1c68cd1..0000000
--- a/apps/mobile/components/authenticated-redirect.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { useConvexAuth } from "@convex-dev/auth/react"
-import { Redirect } from "expo-router"
-
-import { LoadingView } from "@/components/ui/primitives"
-
-export function AuthenticatedRedirect() {
- const auth = useConvexAuth()
-
- if (!auth) {
- return
- }
-
- const { isLoading, isAuthenticated } = auth
-
- if (isLoading) {
- return
- }
-
- if (!isAuthenticated) {
- return
- }
-
- return
-}
diff --git a/apps/mobile/contexts/convex-app.tsx b/apps/mobile/contexts/convex-app.tsx
index 1fc934d..31dd507 100644
--- a/apps/mobile/contexts/convex-app.tsx
+++ b/apps/mobile/contexts/convex-app.tsx
@@ -22,11 +22,11 @@ export function ConvexAppProvider({ children }: { children: ReactNode }) {
return
}
await clearStoredAuthTokens(config.convexUrl)
- try {
- await clearAppIntentCatalogs()
- } finally {
- setAuthEpoch((epoch) => epoch + 1)
- }
+ setAuthEpoch((epoch) => epoch + 1)
+ // Native catalog cleanup can be slow; it must not hold the signed-in UI open.
+ void clearAppIntentCatalogs().catch((error) => {
+ console.warn("Could not clear app intent catalogs.", error)
+ })
}, [config])
if (!client || !config) {
diff --git a/apps/mobile/lib/session.ts b/apps/mobile/lib/session.ts
index 2952f4f..305aa4c 100644
--- a/apps/mobile/lib/session.ts
+++ b/apps/mobile/lib/session.ts
@@ -1,22 +1,32 @@
-import type { useRouter } from "expo-router"
-
-import { clearAppIntentCatalogs } from "@/lib/app-intent-handled"
import { resetPlaybackStores } from "@otunes/convex/client/playback-store"
import { clearPersistentCache } from "@/lib/persistent-cache"
-type AppRouter = ReturnType
-
/** Forgets this device's cached library and playback state. */
export async function clearLocalData() {
resetPlaybackStores()
- await Promise.all([clearPersistentCache(), clearAppIntentCatalogs()])
+ await clearPersistentCache()
}
-export async function signOutToSignIn(
- router: Pick,
- invalidateSession: () => Promise
+/** Root route guards leave the app when the session or server is cleared. */
+export async function signOut(invalidateSession: () => Promise) {
+ try {
+ await invalidateSession()
+ } finally {
+ await clearLocalData()
+ }
+}
+
+export async function changeServer(
+ invalidateSession: () => Promise,
+ clearServer: () => Promise
) {
- await invalidateSession()
- await clearLocalData()
- router.replace("/signin")
+ try {
+ await invalidateSession()
+ } finally {
+ try {
+ await clearServer()
+ } finally {
+ await clearLocalData()
+ }
+ }
}