From 659a396fbbc0e5b6d79ac926d8c9cd85dcaf2115 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 11 Mar 2022 12:59:10 +0100 Subject: [PATCH] Login fixed --- .eslintrc.js | 6 ++ jest.config.js | 1 + quasar.conf.js | 2 +- src/boot/axios.ts | 20 +++++++ src/components/Topbar.vue | 54 ++++++++++++++++++ src/components/UserPanel.vue | 104 +++++++++++++++++++++++++++++++++++ src/composables/useRole.ts | 3 +- src/i18n/en/index.ts | 29 +++++++++- src/i18n/es/index.ts | 29 ++++++++++ src/i18n/index.ts | 2 + src/layouts/Main.vue | 31 +++++++---- src/pages/Login/Login.vue | 56 ++++++++++--------- src/router/index.ts | 14 ++++- src/router/routes.ts | 4 +- 14 files changed, 311 insertions(+), 44 deletions(-) create mode 100644 src/components/Topbar.vue create mode 100644 src/components/UserPanel.vue create mode 100644 src/i18n/es/index.ts diff --git a/.eslintrc.js b/.eslintrc.js index e84d45a45..f51cd2502 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -80,6 +80,12 @@ module.exports = { // TypeScript quotes: ['warn', 'single', { avoidEscape: true }], '@typescript-eslint/explicit-function-return-type': 'off', + "@typescript-eslint/unbound-method": "off", + + + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-floating-promises': 'off', // allow debugger during development only 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', diff --git a/jest.config.js b/jest.config.js index ba0d701f6..22d55b033 100755 --- a/jest.config.js +++ b/jest.config.js @@ -58,6 +58,7 @@ module.exports = { '^src/(.*)$': '/src/$1', '^app/(.*)$': '/$1', '^components/(.*)$': '/src/components/$1', + '^composables/(.*)$': '/src/composables/$1', '^layouts/(.*)$': '/src/layouts/$1', '^pages/(.*)$': '/src/pages/$1', '^assets/(.*)$': '/src/assets/$1', diff --git a/quasar.conf.js b/quasar.conf.js index 0903e1131..3e3de621f 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -107,7 +107,7 @@ module.exports = configure(function (ctx) { // directives: [], // Quasar plugins - plugins: [], + plugins: ['Notify'], }, // animations: 'all', // --- includes all animations diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 29a45500f..2fff62c64 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -1,6 +1,10 @@ import { boot } from 'quasar/wrappers'; import axios, { AxiosInstance } from 'axios'; +import { useSession } from 'src/composables/useSession'; +const { getToken } = useSession(); + + declare module '@vue/runtime-core' { interface ComponentCustomProperties { $axios: AxiosInstance; @@ -15,6 +19,22 @@ declare module '@vue/runtime-core' { // for each client) const api = axios.create({ baseURL: 'https://api.example.com' }); +axios.interceptors.request.use( + function (context) { + const token = getToken(); + + if (token.length && context.headers) { + context.headers.Authorization = token; + } + + return context; + }, + function (error) { + return Promise.reject(error); + } +); + + export default boot(({ app }) => { // for use inside Vue files (Options API) through this.$axios and this.$api diff --git a/src/components/Topbar.vue b/src/components/Topbar.vue new file mode 100644 index 000000000..1534c0a2e --- /dev/null +++ b/src/components/Topbar.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue new file mode 100644 index 000000000..92125dc46 --- /dev/null +++ b/src/components/UserPanel.vue @@ -0,0 +1,104 @@ + + + diff --git a/src/composables/useRole.ts b/src/composables/useRole.ts index 6ce950f7a..100112ce7 100644 --- a/src/composables/useRole.ts +++ b/src/composables/useRole.ts @@ -1,4 +1,4 @@ -import store from '@/store'; +/* import store from '@/store'; export function useRole() { function hasAny(roles: string[]): boolean { @@ -15,3 +15,4 @@ export function useRole() { hasAny, }; } + */ \ No newline at end of file diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts index 250dbd46c..5d5855db4 100644 --- a/src/i18n/en/index.ts +++ b/src/i18n/en/index.ts @@ -2,6 +2,31 @@ // so you can safely delete all default props below export default { - failed: 'Action failed', - success: 'Action was successful', + 'globals': { + 'lang': { + 'es': 'Spanish', + 'en': 'English' + } + }, + 'errors': { + 'statusUnauthorized': 'Access denied', + 'statusInternalServerError': 'An internal server error has ocurred' + }, + 'login': { + 'title': 'Login', + 'username': 'Username', + 'password': 'Password', + 'submit': 'Log in', + 'keepLogin': 'Keep me logged in', + 'loginSuccess': 'You have successfully logged in', + 'loginError': 'Invalid username or password' + }, + 'customer': {}, + 'components': { + 'topbar': {}, + 'userPanel': { + 'settings': 'Settings', + 'logOut': 'Log Out' + } + } }; diff --git a/src/i18n/es/index.ts b/src/i18n/es/index.ts new file mode 100644 index 000000000..2753e4527 --- /dev/null +++ b/src/i18n/es/index.ts @@ -0,0 +1,29 @@ +export default { + 'globals': { + 'lang': { + 'es': 'Español', + 'en': 'Inglés' + } + }, + 'errors': { + 'statusUnauthorized': 'Acceso denegado', + 'statusInternalServerError': 'Ha ocurrido un error interno del servidor' + }, + 'login': { + 'title': 'Iniciar sesión', + 'username': 'Nombre de usuario', + 'password': 'Contraseña', + 'submit': 'Iniciar sesión', + 'keepLogin': 'Mantener sesión iniciada', + 'loginSuccess': 'Inicio de sesión correcto', + 'loginError': 'Nombre de usuario o contraseña incorrectos' + }, + 'customer': {}, + 'components': { + 'topbar': {}, + 'userPanel': { + 'settings': 'Configuración', + 'logOut': 'Cerrar sesión' + } + } +} \ No newline at end of file diff --git a/src/i18n/index.ts b/src/i18n/index.ts index b709d1e41..8adbbf885 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -1,5 +1,7 @@ import en from './en'; +import es from './es'; export default { 'en': en, + 'es': es, }; diff --git a/src/layouts/Main.vue b/src/layouts/Main.vue index cc019c959..94a3e2be8 100644 --- a/src/layouts/Main.vue +++ b/src/layouts/Main.vue @@ -13,30 +13,40 @@ > - + - Dashboard + Dashboard - + - Customers + Customers - Tickets + Tickets - Invoice Out + Invoice Out @@ -44,7 +54,7 @@ - Catalog + Catalog @@ -54,7 +64,7 @@ - Drafts + Drafts @@ -67,7 +77,7 @@ diff --git a/src/pages/Login/Login.vue b/src/pages/Login/Login.vue index d3fae6f9d..533cf8004 100644 --- a/src/pages/Login/Login.vue +++ b/src/pages/Login/Login.vue @@ -23,7 +23,13 @@