From c743f6b313f72ade7efe2490f0b96a08a6fe31ef Mon Sep 17 00:00:00 2001 From: toledo Date: Fri, 10 Mar 2023 20:14:38 +0800 Subject: [PATCH] Commiting changes in order to pull initial_front end feature --- src/Components/api/api.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Components/api/api.tsx b/src/Components/api/api.tsx index e69de29..a559656 100644 --- a/src/Components/api/api.tsx +++ b/src/Components/api/api.tsx @@ -0,0 +1,21 @@ +import axios from "axios"; +import { + LoginParams, +} from "../../Interfaces/Interfaces"; + +export function UserLogin(user: LoginParams) { + return axios + .post("http://localhost:8000/api/v1/accounts/token/login/", user) + .then(async (response) => { + localStorage.setItem("token", JSON.stringify(response.data.auth_token)); + console.log( + "Login Success! Stored Token: ", + JSON.parse(localStorage.getItem("token") || "{}") + ); + return true; + }) + .catch((error) => { + console.log("Login Failed: " + error); + return false; + }); + } \ No newline at end of file