Skip to content

Commit

Permalink
updated routes
Browse files Browse the repository at this point in the history
  • Loading branch information
HaythmKenway committed Oct 9, 2024
1 parent 1422e2f commit 83345b6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 38 deletions.
4 changes: 1 addition & 3 deletions app/Backend/database/dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Use the MySQL base image
FROM mysql:9.0
FROM mysql:8.0

ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_DATABASE=nullbyte
ENV MYSQL_USER=nullbyteadmin
ENV MYSQL_PASSWORD=rootpassword
# ENV MYSQL_OPTIONS="--secure-file-priv="

RUN mkdir -p /var/lib/mysql-files

Expand Down
2 changes: 2 additions & 0 deletions app/Backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ urllib3==2.2.3
virtualenv
Werkzeug==3.0.4
wsproto==1.2.0

jira[cli]
66 changes: 47 additions & 19 deletions app/Frontend/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
import { createRouter, createWebHistory } from 'vue-router'
import {useAuthStore} from "../stores/auth"
import { createRouter, createWebHistory } from 'vue-router';
import { useAuthStore } from "../stores/auth";

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
{
path: '/',
redirect: '/login'
redirect: '/dashboard'
},
{
path: '/dashboard',
name: 'home',
component: () => import('../views/HomeView.vue'),
meta: {
breadcrumb: [{ name: 'Dashboard', path: '/dashboard' }]
},
beforeEnter: (to, from, next) => {
const authStore = useAuthStore();
const isAuthenticated = authStore.isAuthenticated;
if (!isAuthenticated) {
next('/login');
} else {
next();
}
}
},
{
path: '/service',
name: 'service',
component: () => import('../views/ServiceDeskView.vue'),
meta: { requiresAuth: true }
meta: {
breadcrumb: [{ name: 'Dashboard', path: '/dashboard' }, { name: 'Service', path: '/service' }],
requiresAuth: true
}
},
{
path: '/complaint',
name: 'complaint',
component: () => import('../views/Complaint.vue'),
meta: {
breadcrumb: [{ name: 'Dashboard', path: '/dashboard' }, { name: 'Complaint', path: '/complaint' }],
requiresAuth: true
}
},
{
path: '/logout',
name: 'logout',
component: () =>{
const authStore=useAuthStore()
component: () => {
const authStore = useAuthStore();
authStore.logout();
},
meta: { requiresAuth: true }
},
{
path: '/login',
name: 'login',
meta: { requiresAuth: false },
component: () => import('../views/LoginView.vue')
component: () => import('../views/LoginView.vue'),
meta: { requiresAuth: false }
}
]
})
});

router.beforeEach((to,from,next)=>{
const authStore=useAuthStore();
const isAuthenticated=authStore.isAuthenticated;
router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
const isAuthenticated = authStore.isAuthenticated;

if(to.meta.requiresAuth && !isAuthenticated){
next({name:'login'})
}
else{
if (to.meta.requiresAuth && !isAuthenticated) {
next({ name: 'login' });
} else {
next();
}
})
});

export default router
export default router;
38 changes: 22 additions & 16 deletions app/Frontend/src/stores/auth.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import { defineStore } from 'pinia';

import router from '../router/';
import { jwtDecode } from "jwt-decode";

const baseUrl = 'http://localhost:5000';

export const useAuthStore = defineStore({
id: 'auth',
state: () => ({
user: JSON.parse(localStorage.getItem('user')),
}),
state: () => {
const user = JSON.parse(localStorage.getItem('user'));
return {
user: user,
username: user ? jwtDecode(user.token).username : null,
upn:user ? jwtDecode(user.token).upn:[]
};
},
getters: {
isAuthenticated: (state)=> !!state.user
isAuthenticated: (state) => !!state.user
},
actions: {
async login(email, password) {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password })
};
const response = await fetch(`${baseUrl}/sso/auth`, requestOptions);
console.log(response)
if (!response.ok) {
if(response.status==401)
return "Invalid credentials!"
};
const response = await fetch(`${baseUrl}/sso/auth`, requestOptions);
console.log(response);
if (!response.ok) {
if (response.status == 401)
return "Invalid credentials!";
else
return "Unknown Error! Try again later"
return "Unknown Error! Try again later";
}

const user = await response.json();
const user = await response.json();
console.log(user.token);
this.user = user.token ? user : null;

this.username=jwtDecode(user.token).username
localStorage.setItem('user', JSON.stringify(this.user));
router.push('/service');
return ""
router.push('/dashboard');
return "";
},
async logout() {
this.user = null;
Expand Down

0 comments on commit 83345b6

Please sign in to comment.