base ui
This commit is contained in:
20
ui/src/stores/index.js
Normal file
20
ui/src/stores/index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { store } from 'quasar/wrappers'
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
/*
|
||||
* If not building with SSR mode, you can
|
||||
* directly export the Store instantiation;
|
||||
*
|
||||
* The function below can be async too; either use
|
||||
* async/await or return a Promise which resolves
|
||||
* with the Store instance.
|
||||
*/
|
||||
|
||||
export default store((/* { ssrContext } */) => {
|
||||
const pinia = createPinia()
|
||||
|
||||
// You can add Pinia plugins here
|
||||
// pinia.use(SomePiniaPlugin)
|
||||
|
||||
return pinia
|
||||
})
|
||||
79
ui/src/stores/login.js
Normal file
79
ui/src/stores/login.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { LocalStorage } from 'quasar'
|
||||
import { api } from 'boot/axios'
|
||||
import { jwtDecode } from "jwt-decode"
|
||||
import Router from 'src/router/index'
|
||||
|
||||
export const sessionName = 'bresSession'
|
||||
|
||||
const defaultState = {
|
||||
LoggedIn: false,
|
||||
Token: '',
|
||||
UsrKSUID: '',
|
||||
ClientKSUID: '',
|
||||
Email: '',
|
||||
Fullname: '',
|
||||
}
|
||||
|
||||
export const useLoginStore = defineStore('login', {
|
||||
state: () => {
|
||||
return JSON.parse(JSON.stringify(defaultState))
|
||||
},
|
||||
getters: {},
|
||||
actions: {
|
||||
|
||||
login (payload) {
|
||||
// kaldıysa önceki session'ı uçuralım
|
||||
LocalStorage.remove(sessionName)
|
||||
const ds = JSON.parse(JSON.stringify(defaultState))
|
||||
Object.assign(this, ds)
|
||||
|
||||
payload['LoggedIn'] = true
|
||||
const pl = JSON.parse(JSON.stringify(payload))
|
||||
Object.assign(this, pl)
|
||||
api.defaults.headers.common['Authorization'] = `Bearer ${payload.Token}`
|
||||
LocalStorage.set(sessionName, payload)
|
||||
},
|
||||
|
||||
logout () {
|
||||
// todo: burada güvenlik zafiyeti var ! backend'de token invalidate edilmeli
|
||||
// bunun için memlist'e ek bir claim tutulabilir
|
||||
// ve jwtAuth verify koduna yazılıabilinir.
|
||||
// örnek : https://dev.to/stevensunflash/a-working-solution-to-jwt-creation-and-invalidation-in-golang-4oe4
|
||||
const ds = JSON.parse(JSON.stringify(defaultState))
|
||||
Object.assign(this, ds)
|
||||
|
||||
api.defaults.headers.common['Authorization'] = ''
|
||||
LocalStorage.remove(sessionName)
|
||||
|
||||
if (Router) {
|
||||
Router.push('/login')
|
||||
//router.push({ path: '/login', replace: true })
|
||||
}
|
||||
},
|
||||
|
||||
updateState (payload) {
|
||||
Object.assign(this, payload)
|
||||
api.defaults.headers.common['Authorization'] = `Bearer ${payload.Token}`
|
||||
},
|
||||
|
||||
load() {
|
||||
const authInfo = LocalStorage.getItem(sessionName)
|
||||
if (authInfo) {
|
||||
const decoded = jwtDecode(authInfo.Token)
|
||||
const now = Date.now() / 1000
|
||||
if (decoded.exp < now) {
|
||||
this.logout()
|
||||
} else {
|
||||
this.updateState(authInfo)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
IsLoggedIn () {
|
||||
return this.LoggedIn
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useLoginStore
|
||||
10
ui/src/stores/store-flag.d.ts
vendored
Normal file
10
ui/src/stores/store-flag.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/* eslint-disable */
|
||||
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
|
||||
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
|
||||
import "quasar/dist/types/feature-flag";
|
||||
|
||||
declare module "quasar/dist/types/feature-flag" {
|
||||
interface QuasarFeatureFlags {
|
||||
store: true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user