⚡️⚡️⚡️ 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
small improvement
daniel31x133dfa53cf0109
diff --git a/apps/mobile/app/login.tsx b/apps/mobile/app/login.tsxindex d856d82a..1ee4eedd 100644--- a/apps/mobile/app/login.tsx+++ b/apps/mobile/app/login.tsx@@ -71,9 +71,9 @@ export default function HomeScreen() {}setShowInstanceField(!showInstanceField);}}- className="mx-8 mt-2 w-fit"+ className="mx-8 mt-2 self-start">- <Text className="text-neutral-content text-sm w-fit">+ <Text className="text-neutral-content text-sm">{!showInstanceField ? "Change host" : "Use default host"}</Text></TouchableOpacity>diff --git a/apps/mobile/store/auth.ts b/apps/mobile/store/auth.tsindex 8b9aee98..4cd487af 100644--- a/apps/mobile/store/auth.ts+++ b/apps/mobile/store/auth.ts@@ -2,6 +2,7 @@ import { create } from "zustand";import * as SecureStore from "expo-secure-store";import { router } from "expo-router";import { MobileAuth } from "@linkwarden/types";+import { Alert } from "react-native";type AuthStore = {auth: MobileAuth;@@ -19,7 +20,7 @@ const useAuthStore = create<AuthStore>((set) => ({auth: {instance: "",session: null,- status: "loading",+ status: "loading" as const,},setAuth: async () => {const session = await SecureStore.getItemAsync("TOKEN");@@ -48,15 +49,27 @@ const useAuthStore = create<AuthStore>((set) => ({console.log("Signing into", instance);if (token) {- await SecureStore.setItemAsync("TOKEN", token);- // make a request to the API to validate the token (TODO)- router.replace("/(tabs)/dashboard");- set({- auth: {- session: token,- instance,- status: "authenticated",+ // make a request to the API to validate the token+ await fetch(instance + "/api/v1/users/me", {+ method: "GET",+ headers: {+ Authorization: `Bearer ${token}`,},+ }).then(async (res) => {+ if (res.ok) {+ await SecureStore.setItemAsync("INSTANCE", instance);+ await SecureStore.setItemAsync("TOKEN", token);+ set({+ auth: {+ session: token,+ instance,+ status: "authenticated",+ },+ });+ router.replace("/(tabs)/dashboard");+ } else {+ Alert.alert("Error", "Invalid token");+ }});} else {await fetch(instance + "/api/v1/session", {@@ -81,24 +94,18 @@ const useAuthStore = create<AuthStore>((set) => ({router.replace("/(tabs)/dashboard");} else {- set({- auth: {- instance,- session: null,- status: "unauthenticated",- },- });+ Alert.alert("Error", "Invalid credentials");}});}},signOut: async () => {await SecureStore.deleteItemAsync("TOKEN");- const instance = await SecureStore.getItemAsync("INSTANCE");+ await SecureStore.deleteItemAsync("INSTANCE");set({auth: {- instance,+ instance: "",session: null,status: "unauthenticated",},