import { Image } from 'expo-image'; import { Link } from 'expo-router'; import { useState } from 'react'; import { KeyboardAvoidingView, Linking, Platform, StyleSheet, Text, View } from 'react-native'; import { api } from '@/lib/api'; import { WEB_URL } from '@/lib/config'; import { useSession } from '@/lib/session'; import { colors, fonts, space } from '@/lib/theme'; import { Screen } from './Screen'; import { Body, Button, Field, Title } from './ui'; export function AuthForm({ mode }: { mode: 'login' | 'register' }) { const { signIn } = useSession(); const [username, setUsername] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const submit = async () => { setBusy(true); setError(null); try { const res = mode === 'login' ? await api.login({ email, password }) : await api.register({ username, email, password }); await signIn(res); // the protected stack swaps to the tabs automatically } catch (err) { setError((err as Error).message); setBusy(false); } }; return ( {mode === 'login' && ( musicshare See what your friends are playing, and open it in your own app. )} {mode === 'register' && ( )} {error && {error}}