import React, { useState } from "react"; import { View, Text, TextInput, TouchableOpacity, ActivityIndicator, KeyboardAvoidingView, Platform, ScrollView, useColorScheme, } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { Ionicons } from "@expo/vector-icons"; import { useAuth } from "../context/AuthContext"; type Mode = "login" | "register"; export default function AuthGate({ onSuccess }: { onSuccess?: () => void }) { const dark = useColorScheme() === "dark"; const { login, register } = useAuth(); const [mode, setMode] = useState("login"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [name, setName] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [showPass, setShowPass] = useState(false); const accent = dark ? "#E07B45" : "#C4622D"; const submit = async () => { setError(""); if (!email || !password) { setError("Please fill in all fields."); return; } setLoading(true); try { if (mode === "login") await login({ email, password }); else await register({ email, password, name }); onSuccess?.(); // ← add this } catch (e: any) { setError(e.message ?? "Something went wrong."); } finally { setLoading(false); } }; const inputBase = ` rounded-xl px-4 py-3.5 text-sm font-sans border ${dark ? "bg-obsidian-100 border-border-dark text-ink-dark" : "bg-parchment-100 border-border-light text-ink-light"} `; return ( {/* Logo / header */} 📰 {mode === "login" ? "Welcome back" : "Create account"} {mode === "login" ? "Sign in to sync your subscriptions" : "Start reading what matters"} {/* Card */} EMAIL PASSWORD setShowPass((v) => !v)} className="absolute right-3 top-3.5" > {error !== "" && ( {error} )} {loading ? : {mode === "login" ? "Sign in" : "Create account"} } {/* Toggle mode */} {mode === "login" ? "Don't have an account? " : "Already have an account? "} { setMode(mode === "login" ? "register" : "login"); setError(""); }}> {mode === "login" ? "Register" : "Sign in"} {/* Continue as guest */} You can still browse and save locally without signing in. ); }