⚡️⚡️⚡️ 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
mobile: remove login and register screens, update navigation
daniel31x13be63d145a659
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex a4df518a..6ae825d0 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -165,10 +165,8 @@ const RootComponent = ({ isLoading }: { isLoading: boolean }) => {},}}/>- <Stack.Screen name="login" />- <Stack.Screen name="register" />- <Stack.Screen name="subscribe" /><Stack.Screen name="index" />+ <Stack.Screen name="subscribe" /><Stack.Screen name="incoming" /><Stack.Screen name="+not-found" /></Stack>diff --git a/apps/mobile/app/login.tsx b/apps/mobile/app/login.tsxdeleted file mode 100644index fca9ce04..00000000--- a/apps/mobile/app/login.tsx+++ /dev/null@@ -1,305 +0,0 @@-import { Button } from "@/components/ui/Button";-import Input from "@/components/ui/Input";-import { rawTheme, ThemeName } from "@/lib/colors";-import useAuthStore from "@/store/auth";-import {- isAtLeastInstanceVersion,- type Config,-} from "@linkwarden/router/config";-import * as AppleAuthentication from "expo-apple-authentication";-import { GoogleSigninButton } from "@react-native-google-signin/google-signin";-import { router } from "expo-router";-import { useColorScheme } from "nativewind";-import { useEffect, useState } from "react";-import {- Dimensions,- Image,- Platform,- Text,- TouchableOpacity,- View,-} from "react-native";-import Svg, { Path } from "react-native-svg";-import {- KeyboardStickyView,- KeyboardToolbar,-} from "react-native-keyboard-controller";-import { SafeAreaView } from "react-native-safe-area-context";--const cloudInstance = "https://cloud.linkwarden.app";--export default function HomeScreen() {- const { auth, signIn, signInWithApple, signInWithGoogle } = useAuthStore();- const { colorScheme } = useColorScheme();- const [method, setMethod] = useState<"password" | "token">("password");- const [isLoading, setIsLoading] = useState(false);- const [appleEnabled, setAppleEnabled] = useState(- Platform.OS === "ios" && (auth.instance || cloudInstance) === cloudInstance- );- const [googleEnabled, setGoogleEnabled] = useState(- (auth.instance || cloudInstance) === cloudInstance- );- const [isCheckingOAuth, setIsCheckingOAuth] = useState(false);-- const [form, setForm] = useState({- user: "",- password: "",- token: "",- instance: auth.instance || cloudInstance,- });-- const [showInstanceField, setShowInstanceField] = useState(- form.instance !== cloudInstance- );-- const instance = form.instance.trim().replace(/\/+$/, "");-- useEffect(() => {- setForm((prev) => ({- ...prev,- instance: auth.instance || cloudInstance,- }));- }, [auth.instance]);-- useEffect(() => {- setShowInstanceField(form.instance !== cloudInstance);- }, [form.instance]);-- useEffect(() => {- setForm((prev) => ({- ...prev,- token: "",- user: "",- password: "",- }));- }, [method]);-- useEffect(() => {- if (!instance) {- setAppleEnabled(false);- setGoogleEnabled(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.status === "authenticated") return null;-- return (- <>- <KeyboardStickyView className="flex-col justify-end h-full bg-base-100 relative">- <View className="flex-col justify-end h-full bg-primary relative">- <View className="my-auto">- <Image- source={require("@/assets/images/linkwarden.png")}- className="w-[120px] h-[120px] mx-auto"- />- </View>- <Text className="text-base-100 text-5xl font-bold ml-8">Login</Text>- <View>- <Text- className="text-base-100 text-2xl mx-8 mt-3"- numberOfLines={1}- >- Login to{" "}- {form.instance === "https://cloud.linkwarden.app"- ? "cloud.linkwarden.app"- : form.instance}- </Text>- <TouchableOpacity- onPress={() => {- if (showInstanceField) {- setForm({- ...form,- instance: "https://cloud.linkwarden.app",- });- }- setShowInstanceField(!showInstanceField);- }}- className="mx-8 mt-1 self-start"- >- <Text className="text-neutral-content text-sm">- {!showInstanceField ? "Change server" : "Use official server"}- </Text>- </TouchableOpacity>- </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"- >- {showInstanceField && (- <Input- className="w-full text-xl p-3 leading-tight h-12"- textAlignVertical="center"- placeholder="Instance URL"- selectTextOnFocus={false}- value={form.instance}- onChangeText={(text) => setForm({ ...form, instance: text })}- />- )}- {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={async () => {- if (- ((form.user && form.password) || form.token) &&- form.instance- ) {- setIsLoading(true);- await signIn(- form.user,- form.password,- form.instance,- form.token- );- setIsLoading(false);- }- }}- >- <Text className="text-white text-xl">Login</Text>- </Button>- {appleEnabled && (- <AppleAuthentication.AppleAuthenticationButton- buttonType={- AppleAuthentication.AppleAuthenticationButtonType.CONTINUE- }- buttonStyle={- colorScheme === "dark"- ? AppleAuthentication.AppleAuthenticationButtonStyle.WHITE- : AppleAuthentication.AppleAuthenticationButtonStyle.BLACK- }- cornerRadius={8}- style={{ width: "100%", height: 48 }}- onPress={() => {- if (isCheckingOAuth) return;- signInWithApple(instance);- }}- />- )}- {googleEnabled && (- <GoogleSigninButton- size={GoogleSigninButton.Size.Wide}- color={- colorScheme === "dark"- ? GoogleSigninButton.Color.Light- : GoogleSigninButton.Color.Dark- }- style={{ width: "100%", height: 48 }}- onPress={() => {- if (isCheckingOAuth) return;- signInWithGoogle(instance);- }}- />- )}- <TouchableOpacity- className="w-fit mx-auto"- onPress={() => router.replace("/register")}- >- <Text className="text-neutral text-center w-fit">- Don't have an account? Sign up- </Text>- </TouchableOpacity>- </SafeAreaView>- </View>- </KeyboardStickyView>- <KeyboardToolbar />- </>- );-}diff --git a/apps/mobile/app/register.tsx b/apps/mobile/app/register.tsxdeleted file mode 100644index 4b74e4bc..00000000--- a/apps/mobile/app/register.tsx+++ /dev/null@@ -1,511 +0,0 @@-import { Button } from "@/components/ui/Button";-import Input from "@/components/ui/Input";-import { rawTheme, ThemeName } from "@/lib/colors";-import useAuthStore from "@/store/auth";-import {- isAtLeastInstanceVersion,- type Config,-} from "@linkwarden/router/config";-import * as AppleAuthentication from "expo-apple-authentication";-import { GoogleSigninButton } from "@react-native-google-signin/google-signin";-import { router } from "expo-router";-import { useColorScheme } from "nativewind";-import { useEffect, useState } from "react";-import {- ActivityIndicator,- Alert,- Dimensions,- Image,- Platform,- Text,- TouchableOpacity,- View,-} from "react-native";-import Svg, { Path } from "react-native-svg";-import {- KeyboardStickyView,- KeyboardToolbar,-} from "react-native-keyboard-controller";-import { SafeAreaView } from "react-native-safe-area-context";--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 RegisterScreen() {- const {- auth,- signUp,- signInWithApple,- signInWithGoogle,- requestVerificationEmail,- } = useAuthStore();- const { colorScheme } = useColorScheme();- 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 [appleEnabled, setAppleEnabled] = useState(- Platform.OS === "ios" && (auth.instance || cloudInstance) === cloudInstance- );- const [googleEnabled, setGoogleEnabled] = useState(- (auth.instance || cloudInstance) === cloudInstance- );- const [isCheckingOAuth, setIsCheckingOAuth] = useState(false);- const [sentTo, setSentTo] = useState<{- email: string;- instance: string;- } | null>(null);- const [form, setForm] = useState({- name: "",- username: "",- email: "",- password: "",- passwordConfirmation: "",- instance: auth.instance || cloudInstance,- });- const [showInstanceField, setShowInstanceField] = useState(- form.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(() => {- setShowInstanceField(form.instance !== cloudInstance);- }, [form.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 = () =>- setForm((prev) => ({ ...prev, instance: 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]);-- useEffect(() => {- if (!instance) {- setAppleEnabled(false);- setGoogleEnabled(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.status === "authenticated") return null;-- 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.");- router.replace("/login");- }- };-- return (- <>- <KeyboardStickyView className="flex-col justify-end h-full bg-base-100 relative">- <View className="flex-col justify-end h-full bg-primary relative">- <View className="my-auto">- <Image- source={require("@/assets/images/linkwarden.png")}- className="w-[120px] h-[120px] mx-auto"- />- </View>- <Text className="text-base-100 text-5xl font-bold ml-8">- {sentTo ? "Check Email" : "Sign Up"}- </Text>- <View>- <Text- className="text-base-100 text-2xl mx-8 mt-3"- numberOfLines={1}- >- {sentTo ? sentTo.email : `Sign up to ${instanceName}`}- </Text>- {!sentTo && (- <TouchableOpacity- onPress={() => {- if (showInstanceField) {- setForm({ ...form, instance: cloudInstance });- }- setShowInstanceField(!showInstanceField);- }}- className="mx-8 mt-1 self-start"- >- <Text className="text-neutral-content text-sm">- {!showInstanceField ? "Change server" : "Use official server"}- </Text>- </TouchableOpacity>- )}- </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"]}- 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-8 bg-base-100 -mt-2 pb-10 gap-3 w-full px-4"- >- {sentTo ? (- <>- <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>- <TouchableOpacity- className="w-fit mx-auto"- onPress={() => router.replace("/login")}- >- <Text className="text-neutral text-center w-fit">- Back to login- </Text>- </TouchableOpacity>- </>- ) : (- <>- {showInstanceField && (- <Input- className="w-full text-xl p-3 leading-tight h-12"- textAlignVertical="center"- placeholder="Instance URL"- selectTextOnFocus={false}- value={form.instance}- autoCapitalize="none"- onChangeText={(text) =>- setForm({ ...form, instance: text })- }- />- )}- {!!configError && (- <Text className="text-red-500 text-center">- {configError}- </Text>- )}- {isConfigLoading && instance !== cloudInstance && (- <View className="flex-row justify-center items-center gap-2">- <ActivityIndicator />- <Text className="text-neutral">Checking server...</Text>- </View>- )}- {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>- {appleEnabled && (- <AppleAuthentication.AppleAuthenticationButton- buttonType={- AppleAuthentication.AppleAuthenticationButtonType.CONTINUE- }- buttonStyle={- colorScheme === "dark"- ? AppleAuthentication.AppleAuthenticationButtonStyle- .WHITE- : AppleAuthentication.AppleAuthenticationButtonStyle- .BLACK- }- cornerRadius={8}- style={{ width: "100%", height: 48 }}- onPress={() => {- if (isCheckingOAuth) return;- signInWithApple(instance);- }}- />- )}- {googleEnabled && (- <GoogleSigninButton- size={GoogleSigninButton.Size.Wide}- color={- colorScheme === "dark"- ? GoogleSigninButton.Color.Light- : GoogleSigninButton.Color.Dark- }- style={{ width: "100%", height: 48 }}- onPress={() => {- if (isCheckingOAuth) return;- signInWithGoogle(instance);- }}- />- )}- <TouchableOpacity- className="w-fit mx-auto"- onPress={() => router.replace("/login")}- >- <Text className="text-neutral text-center w-fit">- Already registered?- </Text>- </TouchableOpacity>- </>- )}- </SafeAreaView>- </View>- </KeyboardStickyView>- <KeyboardToolbar />- </>- );-}