Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

feat(mobile): add reset password functionality

daniel31x1361ef7c7aaa63
diff --git a/apps/mobile/components/ActionSheets/LoginSheet.tsx b/apps/mobile/components/ActionSheets/LoginSheet.tsx
index 5553cdaa..989d8b7d 100644
--- a/apps/mobile/components/ActionSheets/LoginSheet.tsx
+++ b/apps/mobile/components/ActionSheets/LoginSheet.tsx
@@ -11,6 +11,7 @@ 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 WebViewModal from "@/components/WebViewModal";
import { rawTheme, ThemeName } from "@/lib/colors";
import useAuthStore from "@/store/auth";
import SheetHeader from "./SheetHeader";
@@ -20,12 +21,13 @@ const cloudInstance = "https://cloud.linkwarden.app";
const cleanInstance = (instance: string) => instance.trim().replace(/\/+$/, "");
export default function LoginSheet() {
- const { auth, signIn } = useAuthStore();
+ const { auth, signIn, instanceInfo, fetchInstanceInfo } = 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 [showForgot, setShowForgot] = useState(false);
const [form, setForm] = useState({
user: "",
password: "",
@@ -34,8 +36,15 @@ export default function LoginSheet() {
});
const instance = cleanInstance(form.instance);
- const instanceName =
- instance === cloudInstance ? "cloud.linkwarden.app" : instance;
+
+ const emailEnabled =
+ instance === cloudInstance ||
+ (instanceInfo.instance === instance &&
+ instanceInfo.config?.EMAIL_PROVIDER === true);
+
+ useEffect(() => {
+ fetchInstanceInfo(instance);
+ }, [instance]);
useEffect(() => {
setForm((prev) => ({
@@ -130,18 +139,29 @@ export default function LoginSheet() {
/>
)}
- <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>
+ <View className="flex flex-row">
+ <TouchableOpacity
+ onPress={() =>
+ setMethod(method === "password" ? "token" : "password")
+ }
+ className="w-fit"
+ >
+ <Text className="text-primary w-fit text-center">
+ {method === "password"
+ ? "Login with Access Token"
+ : "Login with Username/Password"}
+ </Text>
+ </TouchableOpacity>
+
+ {emailEnabled && method === "password" && (
+ <TouchableOpacity
+ onPress={() => setShowForgot(true)}
+ className="w-fit ml-auto"
+ >
+ <Text className="text-primary text-right">Forgot password?</Text>
+ </TouchableOpacity>
+ )}
+ </View>
<Button
variant="accent"
@@ -152,6 +172,13 @@ export default function LoginSheet() {
<Text className="text-white text-xl">Login</Text>
</Button>
</ScrollView>
+
+ <WebViewModal
+ visible={showForgot}
+ onClose={() => setShowForgot(false)}
+ title="Forgot Password"
+ uri={`${instance}/forgot`}
+ />
</ActionSheet>
);
}
diff --git a/apps/mobile/components/WebViewModal.tsx b/apps/mobile/components/WebViewModal.tsx
new file mode 100644
index 00000000..585a7636
--- /dev/null
+++ b/apps/mobile/components/WebViewModal.tsx
@@ -0,0 +1,34 @@
+import { Modal, View } from "react-native";
+import { WebView } from "react-native-webview";
+import { useSafeAreaInsets } from "react-native-safe-area-context";
+import SheetHeader from "./ActionSheets/SheetHeader";
+
+type WebViewModalProps = {
+ visible: boolean;
+ onClose: () => void;
+ title: string;
+ uri: string;
+};
+
+export default function WebViewModal({
+ visible,
+ onClose,
+ title,
+ uri,
+}: WebViewModalProps) {
+ const insets = useSafeAreaInsets();
+
+ return (
+ <Modal visible={visible} animationType="slide" onRequestClose={onClose}>
+ <View style={{ flex: 1, paddingTop: insets.top }} className="bg-base-100">
+ <SheetHeader
+ title={title}
+ onClose={onClose}
+ titleClassName="text-2xl"
+ align="left"
+ />
+ {visible && <WebView source={{ uri }} className="flex-1" />}
+ </View>
+ </Modal>
+ );
+}