From 7981b6e9568ab812548982895968ff8546d9a134 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 28 Oct 2024 21:10:16 +0530 Subject: [PATCH] feat: get user by id --- src/api/auth.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/api/auth.ts diff --git a/src/api/auth.ts b/src/api/auth.ts new file mode 100644 index 00000000..34ebcab8 --- /dev/null +++ b/src/api/auth.ts @@ -0,0 +1,15 @@ +import { default as axios } from "axios"; + +export const getUserById = async (userId: string) => { + try { + const response = await axios.get(`http://localhost:8080/auth/user/${userId}`); + if (response.status === 200) { + return response.data; + } else { + throw new Error(`Couldn't get user with id ${userId}`); + } + } catch (error: any) { + console.error(error); + return null; + } +} \ No newline at end of file