⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
feat(mobile): enhance authentication flow
daniel31x139ddf86103072
diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsxindex 012846a5..3645095a 100644--- a/apps/mobile/app/index.tsx+++ b/apps/mobile/app/index.tsx@@ -1,77 +1,300 @@import { Button } from "@/components/ui/Button";import { rawTheme, ThemeName } from "@/lib/colors";import useAuthStore from "@/store/auth";-import { Redirect, router } from "expo-router";+import {+ isAtLeastInstanceVersion,+ type Config,+} from "@linkwarden/router/config";+import { FontAwesome } from "@expo/vector-icons";+import { Redirect } from "expo-router";+import { ChevronDown, CircleHelp } from "lucide-react-native";import { useColorScheme } from "nativewind";-import { View, Text, Dimensions, TouchableOpacity, Image } from "react-native";+import { useEffect, useState } from "react";+import {+ Dimensions,+ Image,+ Platform,+ Text,+ TouchableOpacity,+ View,+} from "react-native";import { SheetManager } from "react-native-actions-sheet";import Svg, { Path } from "react-native-svg";-import Animated, { SlideInDown } from "react-native-reanimated";+import Animated, { FadeIn } from "react-native-reanimated";import { SafeAreaView } from "react-native-safe-area-context";+import { KeyboardToolbar } from "react-native-keyboard-controller";+import * as DropdownMenu from "zeego/dropdown-menu";++const cloudInstance = "https://cloud.linkwarden.app";++const displayInstance = (instance: string | null | undefined) =>+ (instance || cloudInstance).replace(/^https?:\/\//, "").replace(/\/+$/, "");export default function HomeScreen() {- const { auth } = useAuthStore();+ const { auth, setInstance, signInWithApple, signInWithGoogle } =+ useAuthStore();const { colorScheme } = useColorScheme();+ const theme = rawTheme[colorScheme as ThemeName];+ const serverName = displayInstance(auth.instance);+ const instance = (auth.instance || cloudInstance).trim().replace(/\/+$/, "");+ const [appleEnabled, setAppleEnabled] = useState(+ Platform.OS === "ios" && instance === cloudInstance+ );+ const [googleEnabled, setGoogleEnabled] = useState(+ instance === cloudInstance+ );+ const [isCheckingOAuth, setIsCheckingOAuth] = useState(false);++ const openLoginSheet = () => {+ void SheetManager.show("login-sheet");+ };++ const openSignUpSheet = () => {+ void SheetManager.show("sign-up-sheet");+ };++ const setCloudServer = () => {+ void setInstance(cloudInstance);+ };++ const openSelfHostedSheet = () => {+ requestAnimationFrame(() => {+ void SheetManager.show("self-hosted-server-sheet");+ });+ };++ const serverOptions = [+ {+ key: "cloud",+ title: "Cloud (Default)",+ onSelect: setCloudServer,+ className: "font-bold",+ },+ {+ key: "self-hosted",+ title: "Self-hosted",+ onSelect: openSelfHostedSheet,+ },+ ];+ const orderedServerOptions =+ Platform.OS === "ios" ? [...serverOptions].reverse() : serverOptions;+ const ssoProviderText =+ appleEnabled && googleEnabled+ ? "Apple or Google"+ : appleEnabled+ ? "Apple"+ : "Google";++ useEffect(() => {+ if (!instance) {+ setAppleEnabled(false);+ setGoogleEnabled(false);+ setIsCheckingOAuth(false);+ return;+ }++ setAppleEnabled(Platform.OS === "ios" && instance === cloudInstance);+ setGoogleEnabled(instance === cloudInstance);+ setIsCheckingOAuth(true);+ let active = true;+ const timer = setTimeout(async () => {+ try {+ const [configRes, loginsRes] = await Promise.all([+ fetch(`${instance}/api/v1/config`),+ fetch(`${instance}/api/v1/logins`),+ ]);++ if (!active || !configRes.ok || !loginsRes.ok) return;++ const config = ((await configRes.json())?.response ??+ null) as Config | null;+ const logins = await loginsRes.json().catch(() => null);+ const versionOk = isAtLeastInstanceVersion(+ config?.INSTANCE_VERSION,+ "v2.15.0"+ );+ const hasApple =+ logins?.buttonAuths?.some(+ (b: { method?: string }) => b.method === "apple"+ ) === true;+ const hasGoogle =+ logins?.buttonAuths?.some(+ (b: { method?: string }) => b.method === "google"+ ) === true;++ if (active) {+ setAppleEnabled(Platform.OS === "ios" && hasApple && versionOk);+ setGoogleEnabled(hasGoogle && versionOk);+ }+ } catch {+ } finally {+ if (active) setIsCheckingOAuth(false);+ }+ }, 400);++ return () => {+ active = false;+ clearTimeout(timer);+ };+ }, [instance]);if (auth.session) {return <Redirect href="/dashboard" />;}return (- <Animated.View- entering={SlideInDown.springify(500).damping(100).stiffness(300)}- className="flex-col justify-end h-full"- >- <View className="h-full bg-primary relative">- <View className="my-auto">- <Image- source={require("@/assets/images/linkwarden.png")}- className="w-[120px] h-[120px] mx-auto"- />- <Text className="text-base-100 text-4xl font-semibold mt-7 mx-auto">- Linkwarden- </Text>- </View>- <View>- <Text className="text-base-100 text-xl text-center font-semibold mx-4 mt-3">- Welcome to the official mobile app for Linkwarden!- </Text>-- <Text className="text-base-100 text-xl text-center mx-4 mt-3">- Expect regular improvements and new features as we continue refining- the experience.- </Text>- </View>- <Svg- viewBox="0 0 1440 320"- width={Dimensions.get("screen").width}- height={Dimensions.get("screen").width * (320 / 1440) + 2}- >- <Path- fill={rawTheme[colorScheme as ThemeName]["base-100"]}- fill-opacity="1"- d="M0,256L48,234.7C96,213,192,171,288,176C384,181,480,235,576,266.7C672,299,768,309,864,277.3C960,245,1056,171,1152,122.7C1248,75,1344,53,1392,42.7L1440,32L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"- />- </Svg>- <SafeAreaView- edges={["bottom"]}- className="flex-col justify-end h-auto duration-100 pt-10 bg-base-100 -mt-2 pb-10 gap-4 w-full px-4"- >- <Button- variant="accent"- size="lg"- onPress={() => router.navigate("/login")}+ <>+ <Animated.View entering={FadeIn} className="flex-col justify-end h-full">+ <View className="h-full bg-primary relative">+ <SafeAreaView edges={["top"]} className="absolute top-0 right-0 z-10">+ <TouchableOpacity+ activeOpacity={0.7}+ accessibilityRole="button"+ accessibilityLabel="Need help?"+ className="mr-4 mt-2 items-center justify-center rounded-full"+ onPress={() => SheetManager.show("support-sheet")}+ >+ <CircleHelp size={25} color={theme["base-100"]} />+ </TouchableOpacity>+ </SafeAreaView>++ <View className="my-auto">+ <Image+ source={require("@/assets/images/linkwarden.png")}+ className="w-[120px] h-[120px] mx-auto"+ />+ <Text className="text-base-100 text-4xl font-semibold mt-7 mx-auto">+ Linkwarden+ </Text>+ </View>+ <View>+ <Text className="text-base-100 text-xl text-center font-semibold mx-4 mt-3">+ Welcome to the official mobile app for Linkwarden!+ </Text>++ <Text className="text-base-100 text-xl text-center mx-4 mt-3">+ Expect regular improvements and new features as we continue+ refining the experience.+ </Text>+ </View>+ <Svg+ viewBox="0 0 1440 320"+ width={Dimensions.get("screen").width}+ height={Dimensions.get("screen").width * (320 / 1440) + 2}>- <Text className="text-white text-xl">Get Started</Text>- </Button>- <TouchableOpacity- className="w-fit mx-auto"- onPress={() => SheetManager.show("support-sheet")}+ <Path+ fill={rawTheme[colorScheme as ThemeName]["base-100"]}+ fillOpacity={1}+ d="M0,256L48,234.7C96,213,192,171,288,176C384,181,480,235,576,266.7C672,299,768,309,864,277.3C960,245,1056,171,1152,122.7C1248,75,1344,53,1392,42.7L1440,32L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"+ />+ </Svg>+ <SafeAreaView+ edges={["bottom"]}+ className="flex-col justify-end h-auto duration-100 pt-10 bg-base-100 -mt-2 pb-10 gap-4 w-full px-4">- <Text className="text-neutral text-center w-fit">Need help?</Text>- </TouchableOpacity>- </SafeAreaView>- </View>- </Animated.View>+ <View className="flex-row gap-3">+ <Button+ variant="accent"+ size="lg"+ className="flex-1 px-4"+ onPress={openSignUpSheet}+ >+ <Text className="text-white text-xl">Sign Up</Text>+ </Button>+ <Button+ variant="outline"+ size="lg"+ className="flex-1 px-4"+ onPress={openLoginSheet}+ >+ <Text className="text-base-content text-xl">Login</Text>+ </Button>+ </View>++ {(appleEnabled || googleEnabled) && (+ <View className="flex-row items-center justify-between gap-3">+ <View className="flex-1 flex-col">+ <Text className="text-neutral">Or continue using</Text>+ <Text className="font-bold text-base-content">+ {ssoProviderText}+ </Text>+ </View>+ <View className="flex-row justify-end gap-3">+ {appleEnabled && (+ <TouchableOpacity+ activeOpacity={0.7}+ accessibilityRole="button"+ accessibilityLabel="Continue with Apple"+ className="h-12 w-12 items-center justify-center rounded-lg border border-base-content bg-base-100"+ disabled={isCheckingOAuth}+ onPress={() => {+ if (isCheckingOAuth) return;+ void signInWithApple(instance);+ }}+ >+ <FontAwesome+ name="apple"+ size={22}+ color={theme["base-content"]}+ />+ </TouchableOpacity>+ )}+ {googleEnabled && (+ <TouchableOpacity+ activeOpacity={0.7}+ accessibilityRole="button"+ accessibilityLabel="Continue with Google"+ className="h-12 w-12 items-center justify-center rounded-lg border border-base-content bg-base-100"+ disabled={isCheckingOAuth}+ onPress={() => {+ if (isCheckingOAuth) return;+ void signInWithGoogle(instance);+ }}+ >+ <FontAwesome+ name="google"+ size={20}+ color={theme["base-content"]}+ />+ </TouchableOpacity>+ )}+ </View>+ </View>+ )}++ <View className="flex-row items-center justify-center gap-1">+ <Text className="text-neutral text-xs">Server:</Text>+ <DropdownMenu.Root>+ <DropdownMenu.Trigger asChild>+ <TouchableOpacity+ activeOpacity={0.7}+ accessibilityRole="button"+ accessibilityLabel={`Server: ${serverName}`}+ className="flex-row items-center justify-center gap-1"+ >+ <Text className="text-primary text-xs">{serverName}</Text>+ <ChevronDown size={12} color={theme["primary"]} />+ </TouchableOpacity>+ </DropdownMenu.Trigger>++ <DropdownMenu.Content>+ <DropdownMenu.Separator />+ {orderedServerOptions.map((option) => (+ <DropdownMenu.Item+ key={option.key}+ onSelect={option.onSelect}+ className={option.className}+ >+ {option.title}+ </DropdownMenu.Item>+ ))}+ </DropdownMenu.Content>+ </DropdownMenu.Root>+ </View>+ </SafeAreaView>+ </View>+ </Animated.View>+ <KeyboardToolbar />+ </>);}diff --git a/apps/mobile/components/ActionSheets/LoginSheet.tsx b/apps/mobile/components/ActionSheets/LoginSheet.tsxnew file mode 100644index 00000000..5cf00fb2--- /dev/null+++ b/apps/mobile/components/ActionSheets/LoginSheet.tsx@@ -0,0 +1,149 @@+import { useEffect, useState } from "react";+import {+ Dimensions,+ ScrollView,+ Text,+ TouchableOpacity,+ View,+} from "react-native";+import ActionSheet, { SheetManager } from "react-native-actions-sheet";+import { useSafeAreaInsets } from "react-native-safe-area-context";+import { useColorScheme } from "nativewind";+import { Button } from "@/components/ui/Button";+import Input from "@/components/ui/Input";+import { rawTheme, ThemeName } from "@/lib/colors";+import useAuthStore from "@/store/auth";+import SheetHeader from "./SheetHeader";++const cloudInstance = "https://cloud.linkwarden.app";++const cleanInstance = (instance: string) => instance.trim().replace(/\/+$/, "");++export default function LoginSheet() {+ const { auth, signIn } = useAuthStore();+ const { colorScheme } = useColorScheme();+ const insets = useSafeAreaInsets();+ const theme = rawTheme[colorScheme as ThemeName];+ const [method, setMethod] = useState<"password" | "token">("password");+ const [isLoading, setIsLoading] = useState(false);+ const [form, setForm] = useState({+ user: "",+ password: "",+ token: "",+ instance: auth.instance || cloudInstance,+ });++ const instance = cleanInstance(form.instance);+ const instanceName =+ instance === cloudInstance ? "cloud.linkwarden.app" : instance;++ useEffect(() => {+ setForm((prev) => ({+ ...prev,+ instance: auth.instance || cloudInstance,+ }));+ }, [auth.instance]);++ useEffect(() => {+ setForm((prev) => ({+ ...prev,+ token: "",+ user: "",+ password: "",+ }));+ }, [method]);++ const closeSheet = () => {+ void SheetManager.hide("login-sheet");+ };++ const handleLogin = async () => {+ if (!instance || (!form.token && (!form.user || !form.password))) return;++ setIsLoading(true);+ await signIn(form.user, form.password, instance, form.token);+ setIsLoading(false);++ closeSheet();+ };++ return (+ <ActionSheet+ gestureEnabled+ indicatorStyle={{+ display: "none",+ }}+ containerStyle={{+ backgroundColor: theme["base-100"],+ }}+ safeAreaInsets={insets}+ >+ <SheetHeader+ title="Login"+ onClose={closeSheet}+ titleClassName="text-2xl"+ align="left"+ />++ <ScrollView+ keyboardShouldPersistTaps="handled"+ showsVerticalScrollIndicator={false}+ style={{+ maxHeight: Dimensions.get("window").height * 0.78,+ }}+ contentContainerClassName="px-8 pb-5 flex-col gap-4"+ >+ {method === "password" ? (+ <>+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Email or Username"+ value={form.user}+ onChangeText={(text) => setForm({ ...form, user: text })}+ />+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Password"+ secureTextEntry+ value={form.password}+ onChangeText={(text) => setForm({ ...form, password: text })}+ />+ </>+ ) : (+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Access Token"+ secureTextEntry+ value={form.token}+ onChangeText={(text) => setForm({ ...form, token: text })}+ />+ )}++ <TouchableOpacity+ onPress={() =>+ setMethod(method === "password" ? "token" : "password")+ }+ className="w-fit mx-auto"+ >+ <Text className="text-primary w-fit text-center">+ {method === "password"+ ? "Login with Access Token"+ : "Login with Username/Password"}+ </Text>+ </TouchableOpacity>++ <Button+ variant="accent"+ size="lg"+ isLoading={isLoading}+ onPress={handleLogin}+ >+ <Text className="text-white text-xl">Login</Text>+ </Button>+ </ScrollView>+ </ActionSheet>+ );+}diff --git a/apps/mobile/components/ActionSheets/SelfHostedServerSheet.tsx b/apps/mobile/components/ActionSheets/SelfHostedServerSheet.tsxnew file mode 100644index 00000000..365230a1--- /dev/null+++ b/apps/mobile/components/ActionSheets/SelfHostedServerSheet.tsx@@ -0,0 +1,124 @@+import { useEffect, useState } from "react";+import { Alert, Text, View } from "react-native";+import ActionSheet, { SheetManager } from "react-native-actions-sheet";+import { useSafeAreaInsets } from "react-native-safe-area-context";+import { useColorScheme } from "nativewind";+import { Button } from "@/components/ui/Button";+import Input from "@/components/ui/Input";+import { rawTheme, ThemeName } from "@/lib/colors";+import useAuthStore from "@/store/auth";+import SheetHeader from "./SheetHeader";++const cloudInstance = "https://cloud.linkwarden.app";++const cleanInstance = (instance: string) => instance.trim().replace(/\/+$/, "");++const normalizeInstance = (instance: string) => {+ const clean = cleanInstance(instance);++ if (!clean) return "";+ if (/^https?:\/\//i.test(clean)) return clean;++ return `https://${clean}`;+};++const timeout = () =>+ new Promise<Response>((_, reject) =>+ setTimeout(() => reject(new Error("TIMEOUT")), 30000)+ );++export default function SelfHostedServerSheet() {+ const { auth, setInstance } = useAuthStore();+ const { colorScheme } = useColorScheme();+ const insets = useSafeAreaInsets();+ const theme = rawTheme[colorScheme as ThemeName];+ const [server, setServer] = useState(+ auth.instance && auth.instance !== cloudInstance ? auth.instance : ""+ );+ const [isLoading, setIsLoading] = useState(false);++ useEffect(() => {+ setServer(+ auth.instance && auth.instance !== cloudInstance ? auth.instance : ""+ );+ }, [auth.instance]);++ const closeSheet = () => {+ void SheetManager.hide("self-hosted-server-sheet");+ };++ const setSelfHostedServer = async () => {+ const instance = normalizeInstance(server);++ if (!instance)+ return Alert.alert("Error", "Please enter a server address.");++ setIsLoading(true);++ try {+ const res = await Promise.race([+ fetch(`${instance}/api/v1/config`),+ timeout(),+ ]);++ if (!res.ok) {+ return Alert.alert("Error", "Could not verify this server.");+ }++ await setInstance(instance);+ closeSheet();+ } catch (err: any) {+ Alert.alert(+ err?.message === "TIMEOUT" ? "Request timed out" : "Network error",+ err?.message === "TIMEOUT"+ ? "Unable to reach the server in time. Please check the address and try again."+ : "Could not connect to the server. Please check the address and try again."+ );+ } finally {+ setIsLoading(false);+ }+ };++ return (+ <ActionSheet+ gestureEnabled+ indicatorStyle={{+ display: "none",+ }}+ containerStyle={{+ backgroundColor: theme["base-100"],+ }}+ safeAreaInsets={insets}+ >+ <SheetHeader+ title="Self-hosted Server"+ onClose={closeSheet}+ titleClassName="text-2xl"+ align="left"+ />++ <View className="px-8 pb-5 flex-col gap-4">+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="https://example.com"+ selectTextOnFocus={false}+ value={server}+ autoCapitalize="none"+ autoCorrect={false}+ keyboardType="url"+ onChangeText={setServer}+ />++ <Button+ variant="accent"+ size="lg"+ isLoading={isLoading}+ onPress={setSelfHostedServer}+ >+ <Text className="text-white text-xl">Set</Text>+ </Button>+ </View>+ </ActionSheet>+ );+}diff --git a/apps/mobile/components/ActionSheets/Sheets.tsx b/apps/mobile/components/ActionSheets/Sheets.tsxindex 669bc1c9..95fa22ff 100644--- a/apps/mobile/components/ActionSheets/Sheets.tsx+++ b/apps/mobile/components/ActionSheets/Sheets.tsx@@ -13,9 +13,15 @@ import ReadableHighlightSheet, {} from "./ReadableHighlightSheet";import ReadableHighlightsSheet from "./ReadableHighlightsSheet";import ReaderSettingsSheet from "./ReaderSettingsSheet";+import LoginSheet from "./LoginSheet";+import SignUpSheet from "./SignUpSheet";+import SelfHostedServerSheet from "./SelfHostedServerSheet";import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types/global";registerSheet("support-sheet", SupportSheet);+registerSheet("login-sheet", LoginSheet);+registerSheet("sign-up-sheet", SignUpSheet);+registerSheet("self-hosted-server-sheet", SelfHostedServerSheet);registerSheet("add-link-sheet", AddLinkSheet);registerSheet("link-details-sheet", LinkDetailsSheet);registerSheet("edit-link-sheet", EditLinkSheet);@@ -27,6 +33,9 @@ registerSheet("reader-settings-sheet", ReaderSettingsSheet);declare module "react-native-actions-sheet" {interface Sheets {"support-sheet": SheetDefinition;+ "login-sheet": SheetDefinition;+ "sign-up-sheet": SheetDefinition;+ "self-hosted-server-sheet": SheetDefinition;"add-link-sheet": SheetDefinition;"link-details-sheet": SheetDefinition<{payload: {diff --git a/apps/mobile/components/ActionSheets/SignUpSheet.tsx b/apps/mobile/components/ActionSheets/SignUpSheet.tsxnew file mode 100644index 00000000..e1eaec09--- /dev/null+++ b/apps/mobile/components/ActionSheets/SignUpSheet.tsx@@ -0,0 +1,334 @@+import { useEffect, useState } from "react";+import {+ ActivityIndicator,+ Alert,+ Dimensions,+ ScrollView,+ Text,+ View,+} from "react-native";+import ActionSheet, { SheetManager } from "react-native-actions-sheet";+import { useSafeAreaInsets } from "react-native-safe-area-context";+import { useColorScheme } from "nativewind";+import {+ isAtLeastInstanceVersion,+ type Config,+} from "@linkwarden/router/config";+import { Button } from "@/components/ui/Button";+import Input from "@/components/ui/Input";+import { rawTheme, ThemeName } from "@/lib/colors";+import useAuthStore from "@/store/auth";+import SheetHeader from "./SheetHeader";++const cloudInstance = "https://cloud.linkwarden.app";++const cloudConfig: Config = {+ DISABLE_REGISTRATION: null,+ ADMIN: null,+ RSS_POLLING_INTERVAL_MINUTES: null,+ EMAIL_PROVIDER: true,+ MAX_FILE_BUFFER: null,+ USER_CONTENT_DOMAIN: null,+ AI_ENABLED: null,+ INSTANCE_VERSION: null,+ STRIPE_ENABLED: null,+ TRIAL_PERIOD_DAYS: null,+ REQUIRE_CC: null,+};++const cleanInstance = (instance: string) => instance.trim().replace(/\/+$/, "");++const timeout = () =>+ new Promise<Response>((_, reject) =>+ setTimeout(() => reject(new Error("TIMEOUT")), 30000)+ );++export default function SignUpSheet() {+ const { auth, signUp, requestVerificationEmail, setInstance } =+ useAuthStore();+ const { colorScheme } = useColorScheme();+ const insets = useSafeAreaInsets();+ const theme = rawTheme[colorScheme as ThemeName];+ const [isLoading, setIsLoading] = useState(false);+ const [isConfigLoading, setIsConfigLoading] = useState(false);+ const [config, setConfig] = useState<Config | null>(null);+ const [configInstance, setConfigInstance] = useState("");+ const [configError, setConfigError] = useState("");+ const [sentTo, setSentTo] = useState<{+ email: string;+ instance: string;+ } | null>(null);+ const [form, setForm] = useState({+ name: "",+ username: "",+ email: "",+ password: "",+ passwordConfirmation: "",+ instance: auth.instance || cloudInstance,+ });++ const instance = cleanInstance(form.instance);+ const currentConfig =+ instance === cloudInstance+ ? cloudConfig+ : configInstance === instance+ ? config+ : null;+ const emailSignUp = currentConfig?.EMAIL_PROVIDER === true;+ const supportsMobileSignup =+ instance === cloudInstance ||+ isAtLeastInstanceVersion(currentConfig?.INSTANCE_VERSION, "v2.15.0");+ const instanceName =+ instance === cloudInstance ? "cloud.linkwarden.app" : instance;++ useEffect(() => {+ setForm((prev) => ({+ ...prev,+ instance: auth.instance || cloudInstance,+ }));+ }, [auth.instance]);++ useEffect(() => {+ let active = true;++ if (!instance) {+ setConfig(null);+ setConfigInstance("");+ setConfigError("");+ setIsConfigLoading(false);+ return;+ }++ if (instance === cloudInstance) {+ setConfig(null);+ setConfigInstance("");+ setConfigError("");+ setIsConfigLoading(false);+ return;+ }++ setConfig(null);+ setConfigError("");+ setIsConfigLoading(true);++ const timer = setTimeout(async () => {+ try {+ const res = await Promise.race([+ fetch(`${instance}/api/v1/config`),+ timeout(),+ ]);+ const data = await res.json().catch(() => null);++ if (!active) return;++ if (res.ok) {+ const nextConfig = data.response as Config;++ if (+ nextConfig.EMAIL_PROVIDER === true &&+ !isAtLeastInstanceVersion(nextConfig.INSTANCE_VERSION, "v2.15.0")+ ) {+ const reset = () => {+ void setInstance(cloudInstance);+ };++ Alert.alert(+ "Sign up through the web",+ "This instance needs to be updated to support mobile sign-up. You can sign up through the web, then come back here to log in.",+ [{ text: "OK", onPress: reset }],+ { onDismiss: reset }+ );+ }++ setConfig(nextConfig);+ setConfigInstance(instance);+ } else {+ setConfigError("Could not load this instance.");+ }+ } catch {+ if (active) setConfigError("Could not reach this instance.");+ } finally {+ if (active) setIsConfigLoading(false);+ }+ }, 400);++ return () => {+ active = false;+ clearTimeout(timer);+ };+ }, [instance]);++ const closeSheet = () => {+ void SheetManager.hide("sign-up-sheet");+ };++ const register = async () => {+ const email = form.email.toLowerCase().trim();+ const username = form.username.toLowerCase().trim();+ const name = form.name.trim();++ if (!currentConfig)+ return Alert.alert("Error", configError || "Please check the instance.");+ else if (currentConfig.DISABLE_REGISTRATION)+ return Alert.alert("Error", "Registration is disabled on this instance.");+ else if (emailSignUp && !supportsMobileSignup)+ return Alert.alert(+ "Sign up through the web",+ "This instance needs to be updated to support mobile sign-up. You can sign up through the web, then come back here to log in."+ );+ else if (+ !name ||+ !form.password ||+ !form.passwordConfirmation ||+ (emailSignUp ? !email : !username)+ )+ return Alert.alert("Error", "Please fill all fields");+ else if (form.password !== form.passwordConfirmation)+ return Alert.alert("Error", "Passwords don't match");+ else if (form.password.length < 8)+ return Alert.alert("Error", "Password must be at least 8 characters");++ setIsLoading(true);+ const created = await signUp({+ name,+ email: emailSignUp ? email : undefined,+ username: emailSignUp ? undefined : username,+ password: form.password,+ instance,+ });+ setIsLoading(false);++ if (!created) return;++ if (emailSignUp) setSentTo({ email, instance });+ else {+ Alert.alert("Account created", "You can log in now.");+ }+ };++ return (+ <ActionSheet+ gestureEnabled+ indicatorStyle={{+ display: "none",+ }}+ containerStyle={{+ backgroundColor: theme["base-100"],+ }}+ safeAreaInsets={insets}+ >+ <SheetHeader+ title={sentTo ? "Check Email" : "Sign Up"}+ onClose={closeSheet}+ titleClassName="text-2xl"+ align="left"+ />++ <ScrollView+ keyboardShouldPersistTaps="handled"+ showsVerticalScrollIndicator={false}+ style={{+ maxHeight: Dimensions.get("window").height * 0.78,+ }}+ contentContainerClassName="px-8 pb-5 flex-col gap-3"+ >+ {sentTo ? (+ <>+ <Text className="text-base-content text-xl" numberOfLines={1}>+ {sentTo.email}+ </Text>+ <Text className="text-base-content text-center text-base px-2">+ We sent you a verification link. After verifying your email, come+ back and log in.+ </Text>+ <Button+ variant="accent"+ size="lg"+ isLoading={isLoading}+ onPress={async () => {+ setIsLoading(true);+ await requestVerificationEmail(sentTo.email, sentTo.instance);+ setIsLoading(false);+ }}+ >+ <Text className="text-white text-xl">Resend Email</Text>+ </Button>+ </>+ ) : (+ <>+ {!!configError && (+ <Text className="text-red-500 text-center">{configError}</Text>+ )}+ {currentConfig?.DISABLE_REGISTRATION && (+ <Text className="text-neutral text-center">+ Registration is disabled on this instance.+ </Text>+ )}+ {currentConfig?.EMAIL_PROVIDER === true &&+ !supportsMobileSignup && (+ <Text className="text-neutral text-center">+ This instance needs to be updated to support mobile sign-up.+ You can sign up through the web, then come back here to log+ in.+ </Text>+ )}+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Display Name"+ value={form.name}+ onChangeText={(text) => setForm({ ...form, name: text })}+ />+ {emailSignUp ? (+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Email"+ value={form.email}+ autoCapitalize="none"+ keyboardType="email-address"+ onChangeText={(text) => setForm({ ...form, email: text })}+ />+ ) : (+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Username"+ value={form.username}+ autoCapitalize="none"+ onChangeText={(text) => setForm({ ...form, username: text })}+ />+ )}+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Password"+ secureTextEntry+ value={form.password}+ onChangeText={(text) => setForm({ ...form, password: text })}+ />+ <Input+ className="w-full text-xl p-3 leading-tight h-12"+ textAlignVertical="center"+ placeholder="Confirm Password"+ secureTextEntry+ value={form.passwordConfirmation}+ onChangeText={(text) =>+ setForm({ ...form, passwordConfirmation: text })+ }+ />+ <Button+ variant="accent"+ size="lg"+ disabled={isConfigLoading}+ isLoading={isLoading}+ onPress={register}+ >+ <Text className="text-white text-xl">Sign Up</Text>+ </Button>+ </>+ )}+ </ScrollView>+ </ActionSheet>+ );+}diff --git a/apps/mobile/components/ActionSheets/SupportSheet.tsx b/apps/mobile/components/ActionSheets/SupportSheet.tsxindex eaa96cbd..cae8d0d3 100644--- a/apps/mobile/components/ActionSheets/SupportSheet.tsx+++ b/apps/mobile/components/ActionSheets/SupportSheet.tsx@@ -28,7 +28,7 @@ export default function SupportSheet() {<ActionSheetgestureEnabledindicatorStyle={{- backgroundColor: rawTheme[colorScheme as ThemeName]["neutral-content"],+ display: "none",}}containerStyle={{backgroundColor: rawTheme[colorScheme as ThemeName]["base-100"],@@ -38,8 +38,8 @@ export default function SupportSheet() {<SheetHeadertitle="Need help?"onClose={closeSheet}+ titleClassName="text-2xl"align="left"- titleClassName="text-2xl font-bold"/><View className="px-8 pb-5 flex-col gap-4">diff --git a/apps/mobile/store/auth.ts b/apps/mobile/store/auth.tsindex 76feb63a..55a9bc5f 100644--- a/apps/mobile/store/auth.ts+++ b/apps/mobile/store/auth.ts@@ -52,6 +52,7 @@ type AuthStore = {email: string,instance: string) => Promise<boolean>;+ setInstance: (instance: string) => Promise<void>;signOut: () => Promise<void>;setAuth: () => Promise<void>;};@@ -146,6 +147,15 @@ const useAuthStore = create<AuthStore>((set) => ({}},requestVerificationEmail,+ setInstance: async (instance) => {+ await SecureStore.setItemAsync("INSTANCE", instance);+ set((state) => ({+ auth: {+ ...state.auth,+ instance,+ },+ }));+ },signUp: async ({ name, username, email, password, instance }) => {try {const res = await Promise.race([@@ -401,8 +411,9 @@ const useAuthStore = create<AuthStore>((set) => ({}},signOut: async () => {+ const instance = await SecureStore.getItemAsync("INSTANCE");+await SecureStore.deleteItemAsync("TOKEN");- await SecureStore.deleteItemAsync("INSTANCE");queryClient.cancelQueries();queryClient.clear();@@ -415,7 +426,7 @@ const useAuthStore = create<AuthStore>((set) => ({set({auth: {- instance: "",+ instance: instance || cloudInstance,session: null,status: "unauthenticated",},