feat(driver-pwa): auth store + ky client + typed driver API (zod)
Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import ky, { type KyInstance } from "ky";
|
||||
import { useAuth } from "@/store/auth";
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE ?? "https://crm.pptaxi.ru/api";
|
||||
|
||||
export const api: KyInstance = ky.create({
|
||||
prefixUrl: API_BASE,
|
||||
timeout: 30_000,
|
||||
retry: { limit: 2, methods: ["get"] },
|
||||
hooks: {
|
||||
beforeRequest: [
|
||||
(request) => {
|
||||
const token = useAuth.getState().token;
|
||||
if (token) request.headers.set("Authorization", `Bearer ${token}`);
|
||||
},
|
||||
],
|
||||
beforeError: [
|
||||
(error) => {
|
||||
if (error.response?.status === 401) useAuth.getState().clear();
|
||||
return error;
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user