aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/search/SearchResult.tsx16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/components/search/SearchResult.tsx b/src/components/search/SearchResult.tsx
index e65be1f4..952f08f7 100644
--- a/src/components/search/SearchResult.tsx
+++ b/src/components/search/SearchResult.tsx
@@ -11,6 +11,11 @@ import {
import RNFetchBlob from 'rn-fetch-blob';
import AsyncStorage from '@react-native-community/async-storage';
import {AVATAR_PHOTO_ENDPOINT} from '../../constants';
+import {UserType} from '../../types';
+const NO_USER: UserType = {
+ userId: '',
+ username: '',
+};
interface SearchResultProps extends ViewProps {
profilePreview: ProfilePreviewType;
@@ -20,15 +25,22 @@ const SearchResult: React.FC<SearchResultProps> = ({
style,
}) => {
const [avatarURI, setAvatarURI] = useState<string | null>(null);
-
+ const [user, setUser] = useState<UserType>(NO_USER);
useEffect(() => {
let mounted = true;
const loadAvatar = async () => {
try {
+ const token = await AsyncStorage.getItem('token');
+ if (!token) {
+ setUser(NO_USER);
+ return;
+ }
const response = await RNFetchBlob.config({
fileCache: true,
appendExt: 'jpg',
- }).fetch('GET', AVATAR_PHOTO_ENDPOINT + `${id}`);
+ }).fetch('GET', AVATAR_PHOTO_ENDPOINT + `${id}`, {
+ Authorization: 'Token ' + token,
+ });
const status = response.info().status;
if (status === 200) {
if (mounted) {