From 81b46581ab79f8f5e9e132e00e5d1b8e9182dd46 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 15 Nov 2020 04:07:33 +0300 Subject: feat: implement authentication --- src/hooks/APIClient.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/hooks/APIClient.ts') diff --git a/src/hooks/APIClient.ts b/src/hooks/APIClient.ts index d3c4542..015191c 100644 --- a/src/hooks/APIClient.ts +++ b/src/hooks/APIClient.ts @@ -6,9 +6,11 @@ type Response = responseInterface; const fetcher = (endpoint: string) => get(endpoint).then(response => response.data); - -export const useUser = (id: string): Response => { - return useSWR(id && `/users/${id}`, fetcher); +export const useUser = (username: string | null): Response => { + return useSWR( + username && `/users?username=${username}`, + (url: string) => get(url).then(response => response.data[0]) + ); }; export const useEvents = (): Response => { -- cgit v1.2.3