diff --git a/app.vue b/app.vue
index 54c3713..2dfae6a 100644
--- a/app.vue
+++ b/app.vue
@@ -7,21 +7,21 @@
diff --git a/axios.config.js b/axios.config.js
index dd8d5b5..30d5271 100644
--- a/axios.config.js
+++ b/axios.config.js
@@ -1,14 +1,30 @@
-import axios from 'axios';
+import axios, {AxiosError} from 'axios';
+import clientsideConfig from './clientsideConfig'
//create axios instance
const Axios = axios.create({
- // baseURL: `https://${serversideConfig.url}:${serversideConfig.port}`,
+ //baseURL: `https://${serversideConfig.url}:${serversideConfig.port}/`,
+ baseURL: `https://${clientsideConfig.url}:${clientsideConfig.port}/`,
headers: {
// 'Accept': 'application/json',
'Content-Type': 'application/json',
//Authorization: `Bearer`,
Accept: "*",
},
+ withCredentials: true,
+ credentials: true,
})
+
+Axios.interceptors.response.use((response) => response, (error) => {
+
+ if (error instanceof AxiosError) {
+ console.error('Status: ', error.response?.status, '\nHeaders: '. error.response?.headers, '\nMessage: '. error.response?.data.message)
+ } else { console.error('Error: ', error); };
+
+ if (error.response?.status === 403) { window.location.href = '/login'; };
+
+ return Promise.reject(error);
+});
+
export default Axios;
diff --git a/backend/controller/users.js b/backend/controller/users.js
index 26c568a..1bd09c4 100644
--- a/backend/controller/users.js
+++ b/backend/controller/users.js
@@ -93,7 +93,15 @@ export const login = async (req, res, next) => {
}
if (bResult) {
// password match
- const token = jwt.sign(
+ const authtoken = jwt.sign(
+ {
+ username: result[0].username,
+ userId: result[0].id,
+ },
+ 'SECRETTUEITKEY',
+ { expiresIn: '300s' } // 5min
+ );
+ const refreshtoken = jwt.sign(
{
username: result[0].username,
userId: result[0].id,
@@ -115,7 +123,7 @@ export const login = async (req, res, next) => {
const results = await ownConn.query(sql1, [dateTimeString, result[0].id]);
return res.status(200).send({
message: 'Logged in!',
- token,
+ token: { authToken: authtoken, refreshToken: refreshtoken },
user: result[0],
});
}
diff --git a/components/LoginForm.vue b/components/LoginForm.vue
index e1a28e9..18ed8b5 100644
--- a/components/LoginForm.vue
+++ b/components/LoginForm.vue
@@ -50,6 +50,7 @@ import { ref } from 'vue';
import Axios from '../axios.config.js';
import clientsideConfig from '../clientsideConfig.js';
+const { signIn } = useAuth()
const router = useRouter();
const darkMode = ref(true);
const isError = ref(false);
@@ -62,13 +63,14 @@ const handleLogin = async () => {
const username = document.getElementById('username-input').value;
const password = document.getElementById('password-input').value;
- const requestBody = {
+ //const requestBody = {
+ const credentials = {
username: username,
password: password,
}
try {
- let res = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/login`, requestBody);
+ /*let res = await Axios.post(`https://${clientsideConfig.url}:${clientsideConfig.port}/api/login`, requestBody);
const sessionToken = useCookie('token', {maxAge: 604800, sameSite: true});
sessionToken.value = res.data.token;
@@ -80,7 +82,10 @@ const handleLogin = async () => {
console.log(res.data.message)
// sucessfully logged in
- router.push('/home')
+ router.push('/home')*/
+ let res = await signIn( credentials, { callbackUrl: '/home' })
+ console.log("res", res)
+
} catch (err) {
// handle the error
console.log(err.response.statusText)
diff --git a/composables/UserObject.ts b/composables/UserObject.ts
new file mode 100644
index 0000000..5661ac8
--- /dev/null
+++ b/composables/UserObject.ts
@@ -0,0 +1,39 @@
+export var UserObjectDefinition: {
+ id: string;
+ username: string;
+ password: string;
+ registered: string;
+ lastLogin: string;
+ fullName: string;
+ email: string;
+ phonenumber: string;
+ address: string;
+ city: string;
+ postcode: string;
+ adminBool: boolean;
+ technician1Bool: boolean;
+ technician2Bool: boolean;
+ technicianMonitoringBool: boolean;
+ merchantBool: boolean;
+ internBool: boolean;
+}
+
+export interface UserObject {
+ id: string;
+ username: string;
+ password: string;
+ registered: string;
+ lastLogin: string;
+ fullName: string;
+ email: string;
+ phonenumber: string;
+ address: string;
+ city: string;
+ postcode: string;
+ adminBool: boolean;
+ technician1Bool: boolean;
+ technician2Bool: boolean;
+ technicianMonitoringBool: boolean;
+ merchantBool: boolean;
+ internBool: boolean;
+}
\ No newline at end of file
diff --git a/layouts/PageHeader.vue b/layouts/PageHeader.vue
index 97470e1..30cb0d2 100644
--- a/layouts/PageHeader.vue
+++ b/layouts/PageHeader.vue
@@ -2,7 +2,7 @@
-
username
+
@@ -12,19 +12,59 @@
+
+