added login and sign Funtion properly

This commit is contained in:
2024-02-22 16:43:08 +01:00
parent 4b193ac5a1
commit 8c18d80737
11 changed files with 230 additions and 102 deletions

View File

@ -1,6 +1,5 @@
import axios, { AxiosError } from 'axios';
import serversideConfig from '../../serversideConfig';
import fs from 'fs';
import https from 'https';
let loginSuccessful = false;
@ -8,31 +7,22 @@ let errorMsg = '';
export default defineEventHandler(async (event) => {
loginSuccessful = false;
const agent = new https.Agent({
rejectUnauthorized: false,
});
const axiosInstance = axios.create({
headers: {
'Content-Type': 'application/json',
Accept: "*",
},
httpsAgent: agent
});
if (event.path.startsWith("/api/login")) {
const body = await readBody(event)
// read the certificate and create agent
const caCert = fs.readFileSync('./certs/server_ca.pem');
// const httpsAgent = new https.Agent({
// keepAlive: true,
// ca: caCert,
// rejectUnauthorized: true,
// });
const agent = new https.Agent({
rejectUnauthorized: false,
});
const axiosInstance = axios.create({
headers: {
'Content-Type': 'application/json',
Accept: "*",
},
httpsAgent: agent
});
// get user object from backend
try {
let res = await axiosInstance.post(`https://${serversideConfig.url}:${serversideConfig.port}/login`, {