Compare commits
No files matched your search
+1
-18
@@ -44,24 +44,7 @@
|
|||||||
[
|
[
|
||||||
"expo-splash-screen",
|
"expo-splash-screen",
|
||||||
{
|
{
|
||||||
"ios": {
|
"backgroundColor": "#000000"
|
||||||
"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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"expo-image",
|
"expo-image",
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { TabBottomAccessory } from "@/components/mini-player"
|
|||||||
import { usePlaybackQueue } from "@/contexts/playback"
|
import { usePlaybackQueue } from "@/contexts/playback"
|
||||||
import { appleMusic, colors } from "@/lib/theme"
|
import { appleMusic, colors } from "@/lib/theme"
|
||||||
|
|
||||||
|
export const unstable_settings = { anchor: "library" }
|
||||||
|
|
||||||
function useRouterTheme() {
|
function useRouterTheme() {
|
||||||
const isDark = useColorScheme() === "dark"
|
const isDark = useColorScheme() === "dark"
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Ionicons } from "@expo/vector-icons"
|
|||||||
import { useAction, useMutation, useQuery } from "convex/react"
|
import { useAction, useMutation, useQuery } from "convex/react"
|
||||||
import { Image } from "expo-image"
|
import { Image } from "expo-image"
|
||||||
import * as ImagePicker from "expo-image-picker"
|
import * as ImagePicker from "expo-image-picker"
|
||||||
import { useRouter } from "expo-router"
|
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import {
|
import {
|
||||||
Pressable,
|
Pressable,
|
||||||
@@ -20,7 +19,7 @@ import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
|
|||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import { initialsFromName } from "@/lib/format"
|
import { initialsFromName } from "@/lib/format"
|
||||||
import { useCachedQuery } from "@/hooks/use-cached-query"
|
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 { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||||
import { showError } from "@/lib/toast"
|
import { showError } from "@/lib/toast"
|
||||||
import type { PlaybackQuality } from "@/lib/urls"
|
import type { PlaybackQuality } from "@/lib/urls"
|
||||||
@@ -73,7 +72,6 @@ const SECTIONS: SectionConfig[] = [
|
|||||||
|
|
||||||
export default function SettingsScreen() {
|
export default function SettingsScreen() {
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const router = useRouter()
|
|
||||||
const user = useCachedQuery(api.auth.currentUser)
|
const user = useCachedQuery(api.auth.currentUser)
|
||||||
const { invalidateSession } = useInvalidateAuthSession()
|
const { invalidateSession } = useInvalidateAuthSession()
|
||||||
const { clearServer } = useServerConfig()
|
const { clearServer } = useServerConfig()
|
||||||
@@ -91,14 +89,19 @@ export default function SettingsScreen() {
|
|||||||
const visibleSections = SECTIONS.filter((item) => !item.admin || isAdmin)
|
const visibleSections = SECTIONS.filter((item) => !item.admin || isAdmin)
|
||||||
|
|
||||||
async function handleSignOut() {
|
async function handleSignOut() {
|
||||||
await signOutToSignIn(router, invalidateSession)
|
try {
|
||||||
|
await signOut(invalidateSession)
|
||||||
|
} catch {
|
||||||
|
showError("Could not clear all local data.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleChangeServer() {
|
async function handleChangeServer() {
|
||||||
await invalidateSession()
|
try {
|
||||||
await clearLocalData()
|
await changeServer(invalidateSession, clearServer)
|
||||||
await clearServer()
|
} catch {
|
||||||
router.replace("/server")
|
showError("Could not clear all local data.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -61,12 +61,14 @@ export default function LibraryScreen() {
|
|||||||
{links.map((link) => (
|
{links.map((link) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={link.href}
|
key={link.href}
|
||||||
style={[styles.row, { borderBottomColor: colors.border }]}
|
style={styles.row}
|
||||||
onPress={() => push(link.href)}
|
onPress={() => push(link.href)}
|
||||||
>
|
>
|
||||||
<LibraryIcon name={link.icon} />
|
<LibraryIcon name={link.icon} />
|
||||||
<Text style={[styles.rowTitle, { color: colors.foreground }]}>{link.title}</Text>
|
<View style={[styles.rowContent, { borderBottomColor: colors.border }]}>
|
||||||
<Ionicons name="chevron-forward" size={16} color={colors.mutedForeground} />
|
<Text style={[styles.rowTitle, { color: colors.foreground }]}>{link.title}</Text>
|
||||||
|
<Ionicons name="chevron-forward" size={16} color={colors.mutedForeground} />
|
||||||
|
</View>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
@@ -111,6 +113,12 @@ const styles = StyleSheet.create({
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
gap: spacing.md,
|
gap: spacing.md,
|
||||||
paddingHorizontal: spacing.lg,
|
paddingHorizontal: spacing.lg,
|
||||||
|
},
|
||||||
|
rowContent: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: spacing.md,
|
||||||
paddingVertical: 14,
|
paddingVertical: 14,
|
||||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,25 +3,22 @@ import {
|
|||||||
useConvexAuth as useServerConvexAuth,
|
useConvexAuth as useServerConvexAuth,
|
||||||
useConvexConnectionState,
|
useConvexConnectionState,
|
||||||
} from "convex/react"
|
} from "convex/react"
|
||||||
import { Redirect, Stack } from "expo-router"
|
import { Stack } from "expo-router"
|
||||||
import { Platform } from "react-native"
|
import { Platform } from "react-native"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
|
|
||||||
import { AppIntentBridge } from "@/components/app-intent-bridge"
|
import { AppIntentBridge } from "@/components/app-intent-bridge"
|
||||||
import { ConvexAuthRecovery } from "@/components/convex-auth-recovery"
|
import { ConvexAuthRecovery } from "@/components/convex-auth-recovery"
|
||||||
import { LoadingView } from "@/components/ui/primitives"
|
|
||||||
import { AddToPlaylistProvider } from "@/contexts/add-to-playlist"
|
import { AddToPlaylistProvider } from "@/contexts/add-to-playlist"
|
||||||
import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
|
import { useInvalidateAuthSession } from "@/contexts/convex-auth-session"
|
||||||
import { FavoritesProvider } from "@/contexts/favorites"
|
import { FavoritesProvider } from "@/contexts/favorites"
|
||||||
import { PlaybackProvider } from "@/contexts/playback"
|
import { PlaybackProvider } from "@/contexts/playback"
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
|
||||||
import { useStackScreenOptions } from "@/lib/navigation"
|
import { useStackScreenOptions } from "@/lib/navigation"
|
||||||
import { AppNavigationSync } from "@/lib/app-navigation"
|
import { AppNavigationSync } from "@/lib/app-navigation"
|
||||||
|
|
||||||
const AUTH_HANDSHAKE_TIMEOUT_MS = 15_000
|
const AUTH_HANDSHAKE_TIMEOUT_MS = 15_000
|
||||||
|
|
||||||
export default function AppLayout() {
|
export default function AppLayout() {
|
||||||
const { config } = useServerConfig()
|
|
||||||
const localAuth = useLocalConvexAuth()
|
const localAuth = useLocalConvexAuth()
|
||||||
const serverAuth = useServerConvexAuth()
|
const serverAuth = useServerConvexAuth()
|
||||||
const { isWebSocketConnected } = useConvexConnectionState()
|
const { isWebSocketConnected } = useConvexConnectionState()
|
||||||
@@ -51,18 +48,6 @@ export default function AppLayout() {
|
|||||||
serverAuth?.isAuthenticated,
|
serverAuth?.isAuthenticated,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (!config) {
|
|
||||||
return <Redirect href="/server" />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!localAuth || localAuth.isLoading) {
|
|
||||||
return <LoadingView />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!localAuth.isAuthenticated) {
|
|
||||||
return <Redirect href="/signin" />
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convex holds queries until the stored token is confirmed, so the app can
|
// Convex holds queries until the stored token is confirmed, so the app can
|
||||||
// render cached data while the server handshake is still in progress.
|
// render cached data while the server handshake is still in progress.
|
||||||
|
|
||||||
@@ -74,7 +59,10 @@ export default function AppLayout() {
|
|||||||
<AddToPlaylistProvider>
|
<AddToPlaylistProvider>
|
||||||
<FavoritesProvider>
|
<FavoritesProvider>
|
||||||
<Stack screenOptions={stackOptions}>
|
<Stack screenOptions={stackOptions}>
|
||||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
<Stack.Screen
|
||||||
|
name="(tabs)"
|
||||||
|
options={{ headerShown: false, animation: "none" }}
|
||||||
|
/>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name="settings"
|
name="settings"
|
||||||
options={{
|
options={{
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import { Redirect } from "expo-router"
|
|
||||||
|
|
||||||
export default function AppIndex() {
|
|
||||||
return <Redirect href="/(app)/(tabs)/home" />
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,7 @@
|
|||||||
import { useConvexAuth } from "@convex-dev/auth/react"
|
import { Stack } from "expo-router"
|
||||||
import { Redirect, Stack } from "expo-router"
|
|
||||||
|
|
||||||
import { LoadingView } from "@/components/ui/primitives"
|
export const unstable_settings = { anchor: "signin" }
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
|
||||||
|
|
||||||
export default function AuthLayout() {
|
export default function AuthLayout() {
|
||||||
const { config, isLoading: serverLoading } = useServerConfig()
|
|
||||||
const auth = useConvexAuth()
|
|
||||||
|
|
||||||
if (serverLoading) {
|
|
||||||
return <LoadingView />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config) {
|
|
||||||
return <Redirect href="/server" />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!auth || auth.isLoading) {
|
|
||||||
return <LoadingView />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auth.isAuthenticated) {
|
|
||||||
return <Redirect href="/(app)/(tabs)/home" />
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Stack screenOptions={{ headerShown: false }} />
|
return <Stack screenOptions={{ headerShown: false }} />
|
||||||
}
|
}
|
||||||
@@ -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 { StatusBar } from "expo-status-bar"
|
||||||
import { useColorScheme } from "react-native"
|
import { useColorScheme } from "react-native"
|
||||||
import { GestureHandlerRootView } from "react-native-gesture-handler"
|
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 { Toaster } from "@/components/ui/toaster"
|
||||||
import { ConvexAppProvider } from "@/contexts/convex-app"
|
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 (
|
||||||
|
<Stack
|
||||||
|
screenOptions={{
|
||||||
|
headerShown: false,
|
||||||
|
animation: "none",
|
||||||
|
contentStyle: { backgroundColor: "#000" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack.Screen name="index" />
|
||||||
|
<Stack.Protected guard={isAuthenticated}>
|
||||||
|
<Stack.Screen name="(app)" />
|
||||||
|
</Stack.Protected>
|
||||||
|
<Stack.Protected guard={Boolean(config) && !isAuthenticated}>
|
||||||
|
<Stack.Screen name="(auth)" />
|
||||||
|
</Stack.Protected>
|
||||||
|
<Stack.Protected guard={!config}>
|
||||||
|
<Stack.Screen name="server" />
|
||||||
|
</Stack.Protected>
|
||||||
|
</Stack>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
const colorScheme = useColorScheme()
|
const colorScheme = useColorScheme()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GestureHandlerRootView style={{ flex: 1 }}>
|
<GestureHandlerRootView style={{ flex: 1, backgroundColor: "#000" }}>
|
||||||
<SafeAreaProvider>
|
<SafeAreaProvider>
|
||||||
<ServerConfigProvider>
|
<ServerConfigProvider>
|
||||||
<ConvexAppProvider>
|
<ConvexAppProvider>
|
||||||
<StatusBar style={colorScheme === "dark" ? "light" : "dark"} />
|
<StatusBar style={colorScheme === "dark" ? "light" : "dark"} />
|
||||||
<Stack screenOptions={{ headerShown: false }}>
|
<ThemeProvider value={navigationTheme}>
|
||||||
<Stack.Screen name="index" />
|
<RootNavigator />
|
||||||
<Stack.Screen name="server" />
|
</ThemeProvider>
|
||||||
<Stack.Screen name="(auth)" />
|
|
||||||
<Stack.Screen name="(app)" />
|
|
||||||
</Stack>
|
|
||||||
<Toaster />
|
<Toaster />
|
||||||
</ConvexAppProvider>
|
</ConvexAppProvider>
|
||||||
</ServerConfigProvider>
|
</ServerConfigProvider>
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
|
import { useConvexAuth } from "@convex-dev/auth/react"
|
||||||
import { Redirect } from "expo-router"
|
import { Redirect } from "expo-router"
|
||||||
|
|
||||||
import { LoadingView } from "@/components/ui/primitives"
|
|
||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import { AuthenticatedRedirect } from "@/components/authenticated-redirect"
|
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const { config, isLoading } = useServerConfig()
|
const { config } = useServerConfig()
|
||||||
|
const auth = useConvexAuth()
|
||||||
if (isLoading) {
|
|
||||||
return <LoadingView />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return <Redirect href="/server" />
|
return <Redirect href="/server" />
|
||||||
}
|
}
|
||||||
|
|
||||||
return <AuthenticatedRedirect />
|
return (
|
||||||
|
<Redirect
|
||||||
|
href={auth?.isAuthenticated ? "/(app)/(tabs)/library" : "/signin"}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useRouter } from "expo-router"
|
import { useState } from "react"
|
||||||
import { useEffect, useState } from "react"
|
|
||||||
import {
|
import {
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
@@ -14,19 +13,12 @@ import { useServerConfig } from "@/contexts/server-config"
|
|||||||
import { spacing, useThemeColors } from "@/lib/theme"
|
import { spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
|
||||||
export default function ServerScreen() {
|
export default function ServerScreen() {
|
||||||
const router = useRouter()
|
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const { config, isLoading, setServerHostname } = useServerConfig()
|
const { setServerHostname } = useServerConfig()
|
||||||
const [hostname, setHostname] = useState("")
|
const [hostname, setHostname] = useState("")
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [submitting, setSubmitting] = useState(false)
|
const [submitting, setSubmitting] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (config?.hostname) {
|
|
||||||
setHostname(config.hostname)
|
|
||||||
}
|
|
||||||
}, [config?.hostname])
|
|
||||||
|
|
||||||
async function handleContinue() {
|
async function handleContinue() {
|
||||||
setError(null)
|
setError(null)
|
||||||
setSubmitting(true)
|
setSubmitting(true)
|
||||||
@@ -38,7 +30,6 @@ export default function ServerScreen() {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
router.replace("/signin")
|
|
||||||
} catch {
|
} catch {
|
||||||
setError(
|
setError(
|
||||||
"Could not save the server address. Check device storage and try again."
|
"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 (
|
return (
|
||||||
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
<SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useAuthActions, useConvexAuth } from "@convex-dev/auth/react"
|
import { useAuthActions } from "@convex-dev/auth/react"
|
||||||
import { Link, useRouter } from "expo-router"
|
import { Link } from "expo-router"
|
||||||
import { useQuery } from "convex/react"
|
import { useQuery } from "convex/react"
|
||||||
import { useEffect, useState } from "react"
|
import { useState } from "react"
|
||||||
import {
|
import {
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
@@ -16,6 +16,7 @@ import { Button, Card, Input } from "@/components/ui/primitives"
|
|||||||
import { useServerConfig } from "@/contexts/server-config"
|
import { useServerConfig } from "@/contexts/server-config"
|
||||||
import { api } from "@otunes/convex/_generated/api"
|
import { api } from "@otunes/convex/_generated/api"
|
||||||
import { spacing, useThemeColors } from "@/lib/theme"
|
import { spacing, useThemeColors } from "@/lib/theme"
|
||||||
|
import { showError } from "@/lib/toast"
|
||||||
|
|
||||||
type AuthFlow = "signIn" | "signUp"
|
type AuthFlow = "signIn" | "signUp"
|
||||||
|
|
||||||
@@ -50,10 +51,8 @@ const copy: Record<
|
|||||||
|
|
||||||
export function AuthForm({ flow }: { flow: AuthFlow }) {
|
export function AuthForm({ flow }: { flow: AuthFlow }) {
|
||||||
const { signIn } = useAuthActions()
|
const { signIn } = useAuthActions()
|
||||||
const auth = useConvexAuth()
|
|
||||||
const router = useRouter()
|
|
||||||
const colors = useThemeColors()
|
const colors = useThemeColors()
|
||||||
const { config } = useServerConfig()
|
const { config, clearServer } = useServerConfig()
|
||||||
const appSettings = useQuery(api.users.getAppSettings)
|
const appSettings = useQuery(api.users.getAppSettings)
|
||||||
const [name, setName] = useState("")
|
const [name, setName] = useState("")
|
||||||
const [email, setEmail] = useState("")
|
const [email, setEmail] = useState("")
|
||||||
@@ -61,12 +60,6 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
|
|||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [submitting, setSubmitting] = useState(false)
|
const [submitting, setSubmitting] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (auth.isAuthenticated) {
|
|
||||||
router.replace("/(app)/(tabs)/home")
|
|
||||||
}
|
|
||||||
}, [auth.isAuthenticated, router])
|
|
||||||
|
|
||||||
const text = copy[flow]
|
const text = copy[flow]
|
||||||
const accountCreationDisabled = appSettings?.disableAccountCreation ?? false
|
const accountCreationDisabled = appSettings?.disableAccountCreation ?? false
|
||||||
const signupsDisabled = flow === "signUp" && accountCreationDisabled
|
const signupsDisabled = flow === "signUp" && accountCreationDisabled
|
||||||
@@ -164,11 +157,16 @@ export function AuthForm({ flow }: { flow: AuthFlow }) {
|
|||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Link href="/server" asChild>
|
<Pressable
|
||||||
<Pressable style={styles.changeServer}>
|
style={styles.changeServer}
|
||||||
<Text style={{ color: colors.mutedForeground }}>Change server</Text>
|
onPress={() =>
|
||||||
</Pressable>
|
void clearServer().catch(() =>
|
||||||
</Link>
|
showError("Could not clear the server address.")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Text style={{ color: colors.mutedForeground }}>Change server</Text>
|
||||||
|
</Pressable>
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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 <LoadingView />
|
|
||||||
}
|
|
||||||
|
|
||||||
const { isLoading, isAuthenticated } = auth
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return <LoadingView />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
|
||||||
return <Redirect href="/signin" />
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Redirect href="/(app)/(tabs)/home" />
|
|
||||||
}
|
|
||||||
@@ -22,11 +22,11 @@ export function ConvexAppProvider({ children }: { children: ReactNode }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
await clearStoredAuthTokens(config.convexUrl)
|
await clearStoredAuthTokens(config.convexUrl)
|
||||||
try {
|
setAuthEpoch((epoch) => epoch + 1)
|
||||||
await clearAppIntentCatalogs()
|
// Native catalog cleanup can be slow; it must not hold the signed-in UI open.
|
||||||
} finally {
|
void clearAppIntentCatalogs().catch((error) => {
|
||||||
setAuthEpoch((epoch) => epoch + 1)
|
console.warn("Could not clear app intent catalogs.", error)
|
||||||
}
|
})
|
||||||
}, [config])
|
}, [config])
|
||||||
|
|
||||||
if (!client || !config) {
|
if (!client || !config) {
|
||||||
|
|||||||
+22
-12
@@ -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 { resetPlaybackStores } from "@otunes/convex/client/playback-store"
|
||||||
import { clearPersistentCache } from "@/lib/persistent-cache"
|
import { clearPersistentCache } from "@/lib/persistent-cache"
|
||||||
|
|
||||||
type AppRouter = ReturnType<typeof useRouter>
|
|
||||||
|
|
||||||
/** Forgets this device's cached library and playback state. */
|
/** Forgets this device's cached library and playback state. */
|
||||||
export async function clearLocalData() {
|
export async function clearLocalData() {
|
||||||
resetPlaybackStores()
|
resetPlaybackStores()
|
||||||
await Promise.all([clearPersistentCache(), clearAppIntentCatalogs()])
|
await clearPersistentCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function signOutToSignIn(
|
/** Root route guards leave the app when the session or server is cleared. */
|
||||||
router: Pick<AppRouter, "replace">,
|
export async function signOut(invalidateSession: () => Promise<void>) {
|
||||||
invalidateSession: () => Promise<void>
|
try {
|
||||||
|
await invalidateSession()
|
||||||
|
} finally {
|
||||||
|
await clearLocalData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function changeServer(
|
||||||
|
invalidateSession: () => Promise<void>,
|
||||||
|
clearServer: () => Promise<void>
|
||||||
) {
|
) {
|
||||||
await invalidateSession()
|
try {
|
||||||
await clearLocalData()
|
await invalidateSession()
|
||||||
router.replace("/signin")
|
} finally {
|
||||||
|
try {
|
||||||
|
await clearServer()
|
||||||
|
} finally {
|
||||||
|
await clearLocalData()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user