Dirty fix for User Info api

This commit is contained in:
keannu125 2023-02-26 12:04:32 +08:00
parent 36f1e3683e
commit 836220f557

View file

@ -30,9 +30,11 @@ export interface user {
export function UserLogin(user: user) { export function UserLogin(user: user) {
return axios return axios
.post("http://localhost:8000/api/v1/accounts/token/login", user) .post("http://localhost:8000/api/v1/accounts/token/login/", user)
.then((response) => { .then(async (response) => {
console.log("Success! Token: " + response.data); console.log("Login Success! Token: " + response.data);
localStorage.setItem("token", response.data);
console.log(await UserInfo());
return true; return true;
}) })
.catch((error) => { .catch((error) => {
@ -42,16 +44,18 @@ export function UserLogin(user: user) {
} }
export function UserInfo() { export function UserInfo() {
const token = localStorage.getItem("token");
return axios return axios
.get("http://localhost:8000/api/v1/accounts/users/me/", { .get("http://localhost:8000/api/v1/accounts/users/me/", {
headers: { Authorization: "Bearer " + "Token hereee!" }, headers: {
Authorization: "Token 8b3a393fc7601a5a1f2a831bc795905c05420782",
},
}) })
.then((response) => { .then((response) => {
if (response.data) { return response.data;
return response.data;
}
}) })
.catch((error) => { .catch((error) => {
console.log("Error in fetching user data"); console.log("Error in fetching user data");
console.log(error);
}); });
} }