diff options
author | Shravya Ramesh <37447613+shravyaramesh@users.noreply.github.com> | 2020-10-07 23:06:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 02:06:32 -0400 |
commit | 45e435dbb4c43cb890eb360413784d0b2e331bc5 (patch) | |
tree | caa1df04c7b5fcc70ba2c48fa780a4cf2d8e5e0d /src/components | |
parent | 0f332655d2b64700623f25912d2610517fb954b6 (diff) |
[TMA 68] Frontend Token Security (#43)
* frontend tma-68 token security
* removed: try catch while storing token to async, unnecessary console.log
* login/registration exception handling and relocation
* Modified promises, applied fetch restriction
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/search/SearchResult.tsx | 16 |
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) { |