added login and sign Funtion properly
This commit is contained in:
@ -1,60 +1,28 @@
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import serversideConfig from '../../serversideConfig';
|
||||
import fs from 'fs';
|
||||
import https from 'https';
|
||||
|
||||
let registeringSuccessful = false;
|
||||
let errorMsg = '';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
registeringSuccessful = 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/signup")) {
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
// do the post request in the backend
|
||||
try {
|
||||
let res = await axiosInstance.post(`https://${serversideConfig.url}:${serversideConfig.port}/signup`, {
|
||||
username: body.username,
|
||||
password: body.password,
|
||||
password_repeat: body.password_repeat,
|
||||
lastLogin: body.lastLogin,
|
||||
fullName: body.fullName,
|
||||
email: body.email,
|
||||
phonenumber: body.phonenumber,
|
||||
address: body.address,
|
||||
city: body.city,
|
||||
postcode: body.postcode,
|
||||
adminBool: body.adminBool,
|
||||
technician1Bool: body.technician1Bool,
|
||||
technician2Bool: body.technician2Bool,
|
||||
technicianMonitoringBool: body.technicianMonitoringBool,
|
||||
merchantBool: body.merchantBool,
|
||||
internBool: body.internBool,
|
||||
});
|
||||
registeringSuccessful = true;
|
||||
|
||||
let res = await axiosInstance.post(`https://${serversideConfig.url}:${serversideConfig.port}/signup`, body);
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
@ -64,6 +32,7 @@ export default defineEventHandler(async (event) => {
|
||||
console.error(axiosError.response.data.message);
|
||||
errorMsg = axiosError.response.data.message;
|
||||
} else if (axiosError.request) {
|
||||
console.log(err)
|
||||
// If error was caused by the request
|
||||
console.error(axiosError.request);
|
||||
} else {
|
||||
@ -78,6 +47,4 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
})
|
||||
|
||||
export { registeringSuccessful, errorMsg };
|
||||
|
||||
registeringSuccessful = false;
|
||||
export { errorMsg };
|
||||
Reference in New Issue
Block a user