first commit

This commit is contained in:
2024-12-27 16:46:43 +07:00
commit 1962bfb8cc
24 changed files with 7415 additions and 0 deletions

19
server/api/auth.ts Normal file
View File

@@ -0,0 +1,19 @@
import axios from "axios";
export default defineEventHandler(async (event) => {
const body = await readBody(event);
// const email = body.email
// const password = body.password
console.log(body.email)
console.log(body.password)
try {
const response = await axios.post("http://10.10.150.129:8082/api/login/" + body);
return response.data
} catch (error) {
console.error("Error posting to surat kontrol API:", error);
throw createError({
statusCode: 500,
statusMessage: "Failed to fetch data from surat kontrol API",
});
}
});

3
server/tsconfig.json Normal file
View File

@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}

19
server/utils/serverApi.ts Normal file
View File

@@ -0,0 +1,19 @@
import {H3Event} from "h3";
import Client from "~/utils/api/client";
export const ServerApi = (event: H3Event) => {
const {apiUrl} = useRuntimeConfig().public;
const accessToken = getCookie(event, 'Authorization');
const refreshToken = getCookie(event, 'Refresh-Token');
console.log(`Access Token: ${accessToken}`);
console.log(`Refresh Token: ${refreshToken}`);
const client = new Client(apiUrl as string, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Refresh-Token': `Bearer ${refreshToken}`
} as HeadersInit
})
return client;
}