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/screens/search | |
| 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/screens/search')
| -rw-r--r-- | src/screens/search/SearchScreen.tsx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/screens/search/SearchScreen.tsx b/src/screens/search/SearchScreen.tsx index 2a2a5a4a..da83ddef 100644 --- a/src/screens/search/SearchScreen.tsx +++ b/src/screens/search/SearchScreen.tsx @@ -16,6 +16,11 @@ import AsyncStorage from '@react-native-community/async-storage'; import {ProfilePreviewType} from '../../types'; import {SEARCH_ENDPOINT} from '../../constants'; import {AuthContext} from '../../routes/authentication'; +import {UserType} from '../../types'; +const NO_USER: UserType = { + userId: '', + username: '', +}; /** * Search Screen for user recommendations and a search @@ -31,6 +36,7 @@ const SearchScreen: React.FC = () => { ); const [searching, setSearching] = useState(false); const top = Animated.useValue(-SCREEN_HEIGHT); + const [user, setUser] = useState<UserType>(NO_USER); useEffect(() => { if (query.length < 3) { setResults([]); @@ -38,8 +44,16 @@ const SearchScreen: React.FC = () => { } const loadResults = async (q: string) => { try { + const token = await AsyncStorage.getItem('token'); + if (!token) { + setUser(NO_USER); + return; + } const response = await fetch(`${SEARCH_ENDPOINT}?query=${q}`, { method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, }); const status = response.status; if (status === 200) { |
