Skip to content

Commit

Permalink
fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdenio committed Feb 10, 2024
1 parent 4d6bb1d commit 4917a82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Login from "./src/pages/login";
import { lightTheme, palette, theme } from "./src/theme";

export default function App() {
const [isSignedIn, setIsSignedIn] = useState<boolean | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [token, setToken] = useState<string | null>(null);

const scheme = useColorScheme();
Expand All @@ -22,17 +22,17 @@ export default function App() {
(async () => {
const token = await SecureStorage.getItemAsync("token");
setToken(token);
setIsLoading(false);
})();
}, []);

useEffect(() => {
setIsSignedIn((s) => (s === null ? !!token || null : !!token));
if (typeof token == "string") SecureStorage.setItemAsync("token", token);
}, [token]);

if (isSignedIn === null) {
if (isLoading) {
return null;
} else if (!isSignedIn) {
} else if (!token) {
return (
<AuthContext.Provider value={{ token, setToken }}>
<Login />
Expand Down
8 changes: 6 additions & 2 deletions src/components/transaction/types/TransferTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useSWR from "swr";
import { StackParamList } from "../../../lib/NavigatorParamList";
import Organization from "../../../lib/types/Organization";
import { TransactionTransfer } from "../../../lib/types/Transaction";
import User from "../../../lib/types/User";
import { renderMoney, statusColor } from "../../../util";
import Badge from "../../Badge";
import UserMention from "../../UserMention";
Expand All @@ -20,9 +21,12 @@ export default function TransferTransaction({
...props
}: TransactionViewProps<TransactionTransfer>) {
const { data: userOrgs } = useSWR<Organization[]>(`/user/organizations`);
const { data: user } = useSWR<User>("/user");

const userInFromOrg = userOrgs?.some((org) => org.id == transfer.from.id);
const userInToOrg = userOrgs?.some((org) => org.id == transfer.to.id);
const userInFromOrg =
user?.admin || userOrgs?.some((org) => org.id == transfer.from.id);
const userInToOrg =
user?.admin || userOrgs?.some((org) => org.id == transfer.to.id);

const navigation =
useNavigation<NativeStackNavigationProp<StackParamList, "Transaction">>();
Expand Down

0 comments on commit 4917a82

Please sign in to comment.