add auth service

This commit is contained in:
Hepatica
2023-11-25 15:05:58 +01:00
parent 32b55d4b5c
commit 999710a59f
7 changed files with 76 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
import { Post } from '../rest/RestMethods.js';
import { BackendApiUrl } from '@/properties/Сonfig.js';
export function
LogIn(authCode) {
return Post(BackendApiUrl + "/LogIn", { code: authCode }).then((data) => {
console.log(data);
return data;
}).catch(error => {
console.log(error)
});
}

View File

@@ -0,0 +1,10 @@
export function
GetAuthCodeFromCurrentPath() {
const currentPath = window.location.pathname;
const parts = currentPath.split('/');
const code = parts[parts.length - 1];
return code;
}

View File

@@ -0,0 +1,21 @@
export async function Post(url = "", data = {}) {
// Default options are marked with *
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
redirect: "follow",
referrerPolicy: "no-referrer",
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.log("Fetch error:", error);
throw error; // Re-throw the error so it can be caught by the calling function
}
}

View File

@@ -1,6 +1,7 @@
<script> <script>
import '@/assets/css/ComponentsStyles/header.css' import '@/assets/css/ComponentsStyles/header.css'
// import { myFunction } from '@/assets/js/AuthService.js'; // import { GetAuthCodeFromCurrentPath } from '@/assets/js/authentication/LoggingMiddleware.js';
import { LogIn } from '@/assets/js/authentication/AuthService.js';
export default { export default {
name: 'Header-Element-page', name: 'Header-Element-page',
@@ -9,6 +10,17 @@ export default {
balance: 25000, balance: 25000,
auth: false auth: false
} }
}, created() {
let authCode = this.$route.query.code;
LogIn(authCode).then(data => {
console.log(data);
// Обработка данных, возвращённых LogIn
this.auth = true; // Обновляем состояние, основываясь на данных
}).catch(error => {
console.log(error)
})
console.log(authCode)
} }
} }
</script> </script>

View File

@@ -0,0 +1,2 @@
// export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net';
export const BackendApiUrl = 'https://localhost:7062';

View File

@@ -6,6 +6,22 @@
// : '/' // : '/'
// } // }
// module.exports = {
// publicPath: '/'
// }
const path = require('path');
module.exports = { module.exports = {
publicPath: '/' // Установка базового URL-адреса для проекта
publicPath: '/',
// Настройка Webpack
configureWebpack: {
resolve: {
alias: {
'@': path.resolve(__dirname, 'src/'), // Настройка алиаса '@' для каталога 'src/'
} }
}
}
};