update add lib,
This commit is contained in:
83
03_source/frontend/src/lib/axios.ts
Normal file
83
03_source/frontend/src/lib/axios.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { CONFIG } from 'src/global-config';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
const axiosInstance = axios.create({ baseURL: CONFIG.serverUrl });
|
||||
|
||||
axiosInstance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => Promise.reject((error.response && error.response.data) || 'Something went wrong!')
|
||||
);
|
||||
|
||||
export default axiosInstance;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export const fetcher = async (args: string | [string, AxiosRequestConfig]) => {
|
||||
try {
|
||||
const [url, config] = Array.isArray(args) ? args : [args];
|
||||
|
||||
const res = await axiosInstance.get(url, { ...config });
|
||||
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export const endpoints = {
|
||||
chat: '/api/chat',
|
||||
kanban: '/api/kanban',
|
||||
calendar: '/api/calendar',
|
||||
auth: {
|
||||
me: '/api/auth/me',
|
||||
signIn: '/api/auth/sign-in',
|
||||
signUp: '/api/auth/sign-up',
|
||||
},
|
||||
mail: {
|
||||
list: '/api/mail/list',
|
||||
details: '/api/mail/details',
|
||||
labels: '/api/mail/labels',
|
||||
},
|
||||
post: {
|
||||
list: '/api/post/list',
|
||||
details: '/api/post/details',
|
||||
latest: '/api/post/latest',
|
||||
search: '/api/post/search',
|
||||
},
|
||||
product: {
|
||||
list: '/api/product/list',
|
||||
details: '/api/product/details',
|
||||
search: '/api/product/search',
|
||||
},
|
||||
user: {
|
||||
list: '/api/user/list',
|
||||
profile: '/api/user/profile',
|
||||
update: '/api/user/update',
|
||||
settings: '/api/user/settings',
|
||||
details: '/api/user/details',
|
||||
},
|
||||
order: {
|
||||
list: '/api/order/list',
|
||||
profile: '/api/order/profile',
|
||||
update: '/api/order/update',
|
||||
settings: '/api/order/settings',
|
||||
details: '/api/order/details',
|
||||
changeStatus: (orderId: string) => `/api/order/changeStatus?orderId=${orderId}`,
|
||||
},
|
||||
invoice: {
|
||||
list: '/api/invoice/list',
|
||||
profile: '/api/invoice/profile',
|
||||
update: '/api/invoice/update',
|
||||
saveInvoice: (invoiceId: string) => `/api/invoice/saveInvoice?invoiceId=${invoiceId}`,
|
||||
settings: '/api/invoice/settings',
|
||||
details: '/api/invoice/details',
|
||||
changeStatus: (invoiceId: string) => `/api/invoice/changeStatus?invoiceId=${invoiceId}`,
|
||||
search: '/api/invoice/search',
|
||||
},
|
||||
};
|
19
03_source/frontend/src/lib/firebase.ts
Normal file
19
03_source/frontend/src/lib/firebase.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { FirebaseApp } from 'firebase/app';
|
||||
import type { Auth as AuthType } from 'firebase/auth';
|
||||
import type { Firestore as FirestoreType } from 'firebase/firestore';
|
||||
|
||||
import { getAuth } from 'firebase/auth';
|
||||
import { initializeApp } from 'firebase/app';
|
||||
import { getFirestore } from 'firebase/firestore';
|
||||
|
||||
import { CONFIG } from 'src/global-config';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
const isFirebase = CONFIG.auth.method === 'firebase';
|
||||
|
||||
export const firebaseApp = isFirebase ? initializeApp(CONFIG.firebase) : ({} as FirebaseApp);
|
||||
|
||||
export const AUTH = isFirebase ? getAuth(firebaseApp) : ({} as AuthType);
|
||||
|
||||
export const FIRESTORE = isFirebase ? getFirestore(firebaseApp) : ({} as FirestoreType);
|
16
03_source/frontend/src/lib/supabase.ts
Normal file
16
03_source/frontend/src/lib/supabase.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
|
||||
import { CONFIG } from 'src/global-config';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
const isSupabase = CONFIG.auth.method === 'supabase';
|
||||
|
||||
const supabaseUrl = CONFIG.supabase.url;
|
||||
const supabaseKey = CONFIG.supabase.key;
|
||||
|
||||
export const supabase = isSupabase
|
||||
? createClient(supabaseUrl, supabaseKey)
|
||||
: ({} as SupabaseClient<any, 'public', any>);
|
Reference in New Issue
Block a user