From 836220f55755d39f5345a93d0b3c300cb834bdd5 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 26 Feb 2023 12:04:32 +0800 Subject: [PATCH] Dirty fix for User Info api --- src/Components/Api/Api.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx index f606974..3f844a2 100644 --- a/src/Components/Api/Api.tsx +++ b/src/Components/Api/Api.tsx @@ -30,9 +30,11 @@ export interface user { export function UserLogin(user: user) { return axios - .post("http://localhost:8000/api/v1/accounts/token/login", user) - .then((response) => { - console.log("Success! Token: " + response.data); + .post("http://localhost:8000/api/v1/accounts/token/login/", user) + .then(async (response) => { + console.log("Login Success! Token: " + response.data); + localStorage.setItem("token", response.data); + console.log(await UserInfo()); return true; }) .catch((error) => { @@ -42,16 +44,18 @@ export function UserLogin(user: user) { } export function UserInfo() { + const token = localStorage.getItem("token"); return axios .get("http://localhost:8000/api/v1/accounts/users/me/", { - headers: { Authorization: "Bearer " + "Token hereee!" }, + headers: { + Authorization: "Token 8b3a393fc7601a5a1f2a831bc795905c05420782", + }, }) .then((response) => { - if (response.data) { - return response.data; - } + return response.data; }) .catch((error) => { console.log("Error in fetching user data"); + console.log(error); }); }