From f4ea6fb6c577d41f72cc33283e42492e03833f00 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 6 May 2023 00:44:46 -0600 Subject: AƱade ruta account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/loaders.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/clients/loaders.ts') diff --git a/src/clients/loaders.ts b/src/clients/loaders.ts index 334f8aa..2af7770 100644 --- a/src/clients/loaders.ts +++ b/src/clients/loaders.ts @@ -1,3 +1,5 @@ +import { redirect } from "react-router-dom"; +import Token from "../lib/token"; import { ApiClient } from "./api_client"; export async function loader({ request }) { @@ -8,6 +10,21 @@ export async function loader({ request }) { return response; } +export async function accountLoader() { + const client = new ApiClient(); + const token = new Token(); + + if(!token.present()) + return redirect("/products"); + + const headers = { + "Authentication": `Bearer ${ token.get() }` + }; + + const response = await client.get("/account", undefined, headers); + return response; +} + export async function productLoader({ params }) { const client = new ApiClient(); const response = await client.getProduct(params.productId); -- cgit v1.2.3