new UI and handle cashing
This commit is contained in:
+9
-202
@@ -1,209 +1,16 @@
|
||||
import 'ant-design-vue/dist/antd.less'
|
||||
import './assets/css/main.less'
|
||||
import 'virtual:uno.css'
|
||||
import {computed, createApp, nextTick, ref, watch} from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import '@unocss/reset/tailwind-compat.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { authenticateWithFingerprint, getToken, isIphone, removeToken } from '@/utils'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import { useWalletStore } from '@/store/walletStore'
|
||||
import { useFundUserStore } from '@/store/fundStore'
|
||||
import VueLazyLoad from 'vue3-lazyload'
|
||||
import VueApexCharts from 'vue3-apexcharts'
|
||||
import { getMe } from '@/api/me'
|
||||
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
|
||||
import { useAuthStore } from '@/store/useAuthStore'
|
||||
import {applyProjectTheme, getConfigApp} from "@/utils/config";
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
import { initPwaInstallCapture } from '@/modules/pwa/manifest'
|
||||
import { bootstrapApp } from '@/app/bootstrap'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(VueLazyLoad, {
|
||||
// options...
|
||||
})
|
||||
app.use(router)
|
||||
app.use(VueApexCharts)
|
||||
|
||||
const userStore = useUserStore()
|
||||
const walletStore = useWalletStore()
|
||||
const fundStore = useFundUserStore()
|
||||
const authStore = useAuthStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
void settingsStore.fetchSettings()
|
||||
const isApple: boolean = isIphone()
|
||||
let isFirst: boolean = true
|
||||
let fingerPosition: boolean = false
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
||||
let hasFingerPrint: boolean = false
|
||||
const userInfo = ref()
|
||||
// userInfo.value = await getMe()
|
||||
// const token = getToken()
|
||||
|
||||
const currentRoute = computed(() => {
|
||||
return router.currentRoute.value.fullPath
|
||||
})
|
||||
|
||||
async function start() {
|
||||
if (getToken()) {
|
||||
// await userStore.getMyInfo()
|
||||
await walletStore.getLimitedPrice()
|
||||
await walletStore.getLimitedBuyGold()
|
||||
await fundStore.getMyFund()
|
||||
}
|
||||
}
|
||||
|
||||
const win = window as Window & { isWhatsappBtnAdded?: boolean }
|
||||
|
||||
export function setTruth() {
|
||||
fingerPosition = true
|
||||
}
|
||||
|
||||
export function setEnableAuthenticate() {
|
||||
fingerPosition = false
|
||||
}
|
||||
|
||||
|
||||
function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name !== 'login') {
|
||||
return next({ name: 'login' }) // Redirect to login
|
||||
} else {
|
||||
return next() // If already on the login page, don't redirect
|
||||
}
|
||||
}
|
||||
|
||||
function goToHome(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name !== 'home') {
|
||||
return next({ name: 'home' }) // Redirect to login
|
||||
} else {
|
||||
return next() // If already on the login page, don't redirect
|
||||
}
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
|
||||
authStore.setLoading(true)
|
||||
console.log(authStore)
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
if (to.name=='giftCard' && getConfigApp('name')!='garoosi')
|
||||
return next({ name: from.name })
|
||||
// Start a new timeout to reset fingerprint after 5 seconds of inactivity
|
||||
if (from.name !== 'login' || from.name !== undefined) {
|
||||
timeoutId = setTimeout(async () => {
|
||||
if (hasFingerPrint) {
|
||||
fingerPosition = false
|
||||
/* fingerPosition = await authenticateWithFingerprint()
|
||||
if (!fingerPosition) {
|
||||
goToLogin(to, next)
|
||||
}*/
|
||||
// isFirst = true;
|
||||
console.log('Fingerprint authentication reset after 5 seconds of inactivity')
|
||||
}
|
||||
}, 180000) // 5 seconds
|
||||
}
|
||||
// If it's the first time the navigation guard runs
|
||||
if (isFirst) {
|
||||
isFirst = false // Set isFirst to false after the first check
|
||||
|
||||
// If the user has a token
|
||||
if (getToken()) {
|
||||
await userStore.getMyInfo()
|
||||
const finger_print= userStore.userInfo.finger_print
|
||||
// console.log(finger_print)
|
||||
// const { finger_print } = await getMe()
|
||||
hasFingerPrint = finger_print
|
||||
// If on an Apple device and fingerprint exists
|
||||
if (isApple && finger_print) {
|
||||
removeToken() // Remove token if fingerprint is found
|
||||
goToLogin(to, next) // Redirect to login
|
||||
}
|
||||
// If not an Apple device and fingerprint exists
|
||||
else if (!isApple && finger_print) {
|
||||
fingerPosition = await authenticateWithFingerprint()
|
||||
|
||||
if (fingerPosition) {
|
||||
return next()
|
||||
}
|
||||
|
||||
goToLogin(to, next)
|
||||
} else {
|
||||
if (to.name === 'login') {
|
||||
return goToHome(to, next)
|
||||
}
|
||||
return next()
|
||||
}
|
||||
} else {
|
||||
// If no token, handle redirect to login or allow access to login or 404
|
||||
if (['login', '404','educate', 'aboutUs'].includes(to.name as string)) {
|
||||
return next() // Allow access to login or 404
|
||||
}
|
||||
goToLogin(to, next) // Redirect to login if no token
|
||||
}
|
||||
}
|
||||
// For subsequent navigations after the first check
|
||||
else {
|
||||
// If the user has passed fingerprint authentication
|
||||
if (fingerPosition) {
|
||||
if (getToken()) {
|
||||
if (to.name === 'login') {
|
||||
return next({ name: from.name || 'home' }) // Redirect to home if trying to access login after authentication
|
||||
}
|
||||
return next() // Proceed to the intended route
|
||||
} else {
|
||||
// If no token, ensure proper redirection to login or 404
|
||||
if (['login', '404','educate', 'aboutUs'].includes(to.name as string)) {
|
||||
return next() // Allow access to login or 404
|
||||
}
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
}
|
||||
// If fingerprint authentication failed or was not done
|
||||
else {
|
||||
if (getToken() && !hasFingerPrint) {
|
||||
authStore.setLoading(false)
|
||||
return next()
|
||||
}
|
||||
|
||||
if (['login', '404', 'educate', 'aboutUs'].includes(to.name as string)) {
|
||||
authStore.setLoading(false)
|
||||
if (to.name === 'login' && !getToken()) {
|
||||
return goToLogin(to, next)
|
||||
}
|
||||
return next()
|
||||
}
|
||||
|
||||
authStore.setLoading(false)
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
}
|
||||
|
||||
authStore.setLoading(false)
|
||||
})
|
||||
app.mount('#app')
|
||||
// if (currentRoute.value !== '/') {
|
||||
// await start()
|
||||
// }
|
||||
|
||||
nextTick(() => {
|
||||
applyProjectTheme()
|
||||
|
||||
const color = window.__APP_CONFIG__?.user?.color
|
||||
const secondary_color = window.__APP_CONFIG__?.user?.secondary_color
|
||||
|
||||
|
||||
if (!color) {
|
||||
console.warn('Primary color not found')
|
||||
return
|
||||
}
|
||||
console.log('APP_CONFIG:', window.__APP_CONFIG__.user.color)
|
||||
document.documentElement.style.setProperty('--App-primary-color', color)
|
||||
document.documentElement.style.setProperty('--App-secondary-color', secondary_color)
|
||||
|
||||
})
|
||||
watch(currentRoute, async () => userStore.userInfo ? '' : await start())
|
||||
|
||||
export {
|
||||
setTruth,
|
||||
setEnableAuthenticate,
|
||||
setFingerPosition,
|
||||
} from '@/app/authBoot'
|
||||
|
||||
initPwaInstallCapture()
|
||||
void bootstrapApp()
|
||||
|
||||
Reference in New Issue
Block a user