feat: Next.js 14 web admin scaffold — auth, sidebar, dashboard, placeholders
This commit is contained in:
29
lib/api.ts
Normal file
29
lib/api.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: 'https://fiberops-api.juankibin.space',
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
if (typeof window !== 'undefined') {
|
||||
const auth = JSON.parse(localStorage.getItem('fiberops_auth') || '{}');
|
||||
if (auth.state?.accessToken) {
|
||||
config.headers.Authorization = `Bearer ${auth.state.accessToken}`;
|
||||
config.headers['x-tenant-slug'] = auth.state.tenantSlug;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
api.interceptors.response.use(
|
||||
(r) => r,
|
||||
(err) => {
|
||||
if (err.response?.status === 401) {
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.removeItem('fiberops_auth');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
31
lib/auth-store.ts
Normal file
31
lib/auth-store.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
roles: string[];
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
accessToken: string | null;
|
||||
tenantSlug: string | null;
|
||||
user: User | null;
|
||||
setAuth: (data: { accessToken: string; tenantSlug: string; user: User }) => void;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
accessToken: null,
|
||||
tenantSlug: null,
|
||||
user: null,
|
||||
setAuth: (data) => set(data),
|
||||
logout: () => set({ accessToken: null, tenantSlug: null, user: null }),
|
||||
}),
|
||||
{ name: 'fiberops_auth' }
|
||||
)
|
||||
);
|
||||
5
lib/query-client.ts
Normal file
5
lib/query-client.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { QueryClient } from '@tanstack/react-query';
|
||||
|
||||
export const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { staleTime: 30_000, retry: 1 } },
|
||||
});
|
||||
Reference in New Issue
Block a user