Initial commit, repo migration

This commit is contained in:
unknown
2024-05-14 22:19:14 +07:00
commit b51b940ac4
137 changed files with 19393 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import axios from 'axios'
import { parseCookies } from 'nookies'
const defaultOptions = {
baseURL: '/api/',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'Access-Control-Allow-Headers':
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
'Access-Control-Allow-Methods': 'GET,DELETE,PATCH,POST,PUT',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
}
// Create instance
const instance = axios.create(defaultOptions)
instance.defaults.withCredentials = true
// Set the AUTH token for any request
instance.interceptors.request.use(function (config) {
const { token } = parseCookies()
config.headers.Authorization = token ? `Bearer ${token}` : ''
return config
})
export default instance
+25
View File
@@ -0,0 +1,25 @@
import axios from 'axios'
const defaultOptions = {
baseURL: '/sakti/api',
headers: {
// 'Content-Type': 'application/json',
// Accept: 'application/json',
Authorization:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c3IiOiJCQURBTiBLRVBFR0FXQUlBTiBORUdBUkEiLCJ1aWQiOiJCS04iLCJyb2wiOiJ3ZWJzZXJ2aWNlIiwia2RzIjoiS0wwODgiLCJrZGIiOiJLTDA4OCIsImtkdCI6IjIwMjIiLCJpYXQiOjE2NDg1Mzk5ODAsIm5iZiI6MTY0ODUzOTM4MCwia2lkIjoiQktOIn0.9DUVDBDqqf7_tWUWyYCjmoLaIr1F953R_aAUmQy5tkc',
},
}
// Create instance
const instance = axios.create(defaultOptions)
// instance.defaults.withCredentials = true
// Set the AUTH token for any request
// instance.interceptors.request.use(function (config) {
// config.headers.Authorization =
// 'Bearer Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c3IiOiJCQURBTiBLRVBFR0FXQUlBTiBORUdBUkEiLCJ1aWQiOiJCS04iLCJyb2wiOiJ3ZWJzZXJ2aWNlIiwia2RzIjoiS0wwODgiLCJrZGIiOiJLTDA4OCIsImtkdCI6IjIwMjIiLCJpYXQiOjE2NDg1Mzk5ODAsIm5iZiI6MTY0ODUzOTM4MCwia2lkIjoiQktOIn0.9DUVDBDqqf7_tWUWyYCjmoLaIr1F953R_aAUmQy5tkc'
// return config
// })
export default instance
+21
View File
@@ -0,0 +1,21 @@
const API_URL = process.env.NEXT_PUBLIC_BACKEND_API
export async function fetchAPI(target, token) {
var requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
Authorization: 'Bearer ' + token,
},
redirect: 'follow',
}
const res = await fetch(API_URL + target, requestOptions)
const json = await res.json()
if (json.errors) {
console.error(json.errors)
throw new Error('Failed to fetch API')
}
return json.data
}