pocketbase login
This commit is contained in:
16
src/App.vue
16
src/App.vue
@@ -1,13 +1,21 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { RouterView } from 'vue-router';
|
import { RouterView, useRoute } from 'vue-router';
|
||||||
import { Sidebar } from './sidebar';
|
import { Sidebar } from './sidebar';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Sidebar />
|
<template v-if="route.name === 'login'">
|
||||||
<div class="main-container">
|
|
||||||
<RouterView />
|
<RouterView />
|
||||||
</div>
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<Sidebar />
|
||||||
|
<div class="main-container">
|
||||||
|
<RouterView />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
12
src/main.ts
12
src/main.ts
@@ -1,15 +1,25 @@
|
|||||||
|
import { providePocketBase } from '@/pocketbase';
|
||||||
import { createApp } from 'vue';
|
import { createApp } from 'vue';
|
||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import { routes } from './routes';
|
import { routes } from './routes';
|
||||||
import './style.css';
|
import './style.css';
|
||||||
|
|
||||||
|
const app = createApp(App);
|
||||||
|
const pb = providePocketBase(app);
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
const app = createApp(App);
|
router.beforeEach(async to => {
|
||||||
|
if (!pb.authStore.isValid && to.name !== 'login') {
|
||||||
|
return { name: 'login' };
|
||||||
|
} else if (pb.authStore.isValid && to.name === 'login') {
|
||||||
|
return { name: 'home' };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.use(router);
|
app.use(router);
|
||||||
|
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|||||||
30
src/pages/Login.vue
Normal file
30
src/pages/Login.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { usePocketBase } from '@/pocketbase';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
const pb = usePocketBase();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const username = ref("");
|
||||||
|
const password = ref("");
|
||||||
|
|
||||||
|
const login = async () => {
|
||||||
|
await pb.collection('users').authWithPassword(username.value, password.value);
|
||||||
|
await router.push('/');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="p-4 mx-auto mt-10 grid justify-center gap-2 w-64">
|
||||||
|
<div class="grid">
|
||||||
|
Login:
|
||||||
|
<input type="text" autocomplete="username" v-model="username" />
|
||||||
|
</div>
|
||||||
|
<div class="grid">
|
||||||
|
Password:
|
||||||
|
<input type="password" autocomplete="password" v-model="password" />
|
||||||
|
</div>
|
||||||
|
<button class="justify-self-end" @click="login" >Login</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -1,13 +1,21 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, getPrice, getPrices, jitaId } from "@/market";
|
import { MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, getPrice, getPrices, jitaId } from "@/market";
|
||||||
import { BuyModal, ScanResult, ScanResultTable } from '@/market/scan';
|
import { BuyModal, ScanResult, ScanResultTable } from '@/market/scan';
|
||||||
import { useStorage } from '@vueuse/core';
|
import { usePocketBase } from "@/pocketbase";
|
||||||
import { onMounted, ref, watch } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
const pb = usePocketBase();
|
||||||
|
|
||||||
|
type MarketScan = {
|
||||||
|
id?: string;
|
||||||
|
owner: string;
|
||||||
|
types: number[];
|
||||||
|
}
|
||||||
|
|
||||||
const buyModal = ref<typeof BuyModal>();
|
const buyModal = ref<typeof BuyModal>();
|
||||||
|
|
||||||
const item = ref("");
|
const item = ref("");
|
||||||
const itemsStorage = useStorage<number[]>('market-scan-items', []);
|
|
||||||
const items = ref<ScanResult[]>([]);
|
const items = ref<ScanResult[]>([]);
|
||||||
const addOrRelaod = async (type: MarketType) => {
|
const addOrRelaod = async (type: MarketType) => {
|
||||||
const typeID = type.id;
|
const typeID = type.id;
|
||||||
@@ -35,15 +43,28 @@ const addItem = async () => {
|
|||||||
addOrRelaod(type);
|
addOrRelaod(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(items, itms => itemsStorage.value = itms.map(i => i.type.id));
|
const getMarketScan = () => pb.collection('marketScans').getFirstListItem<MarketScan>("").catch(() => null);
|
||||||
|
|
||||||
|
watch(items, async itms => {
|
||||||
|
const types = itms.map(i => i.type.id);
|
||||||
|
const marketScan = await getMarketScan();
|
||||||
|
|
||||||
|
if (marketScan?.id) {
|
||||||
|
pb.collection('marketScans').update(marketScan.id, { owner: pb.authStore.model!.id, types });
|
||||||
|
} else {
|
||||||
|
pb.collection('marketScans').create({ owner: pb.authStore.model!.id, types });
|
||||||
|
}
|
||||||
|
});
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (itemsStorage.value.length === 0) {
|
const marketScan = await getMarketScan();
|
||||||
|
|
||||||
|
if (!marketScan || marketScan.types.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prices = await getPrices(await getMarketTypes(itemsStorage.value));
|
const prices = await getPrices(await getMarketTypes(marketScan.types));
|
||||||
|
|
||||||
items.value = await Promise.all(itemsStorage.value.map(async i => {
|
items.value = await Promise.all(marketScan.types.map(async i => {
|
||||||
const price = prices.find(p => p.type.id === i) as MarketTypePrice;
|
const price = prices.find(p => p.type.id === i) as MarketTypePrice;
|
||||||
const history = await getHistory(jitaId, i);
|
const history = await getHistory(jitaId, i);
|
||||||
|
|
||||||
|
|||||||
1
src/pocketbase/index.ts
Normal file
1
src/pocketbase/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './pocketbase';
|
||||||
13
src/pocketbase/pocketbase.ts
Normal file
13
src/pocketbase/pocketbase.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import PocketBase from 'pocketbase';
|
||||||
|
import { App, inject } from 'vue';
|
||||||
|
|
||||||
|
const pocketBaseSymbol = Symbol('pocketBase');
|
||||||
|
|
||||||
|
export const providePocketBase = (app: App) => {
|
||||||
|
const pb = new PocketBase('/pocketbase/');
|
||||||
|
|
||||||
|
app.provide(pocketBaseSymbol, pb);
|
||||||
|
return pb;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const usePocketBase = () => inject<PocketBase>(pocketBaseSymbol)!;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { RouteRecordRaw } from 'vue-router';
|
import { RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
export const routes: RouteRecordRaw[] = [
|
export const routes: RouteRecordRaw[] = [
|
||||||
{ path: '/', component: () => import('@/pages/Index.vue') },
|
{ path: '/', name: 'home', component: () => import('@/pages/Index.vue') },
|
||||||
|
{ path: '/login', name: 'login', component: () => import('@/pages/Login.vue') },
|
||||||
{ path: '/reprocess', component: () => import('@/pages/Reprocess.vue') },
|
{ path: '/reprocess', component: () => import('@/pages/Reprocess.vue') },
|
||||||
{ path: '/market', component: () => import('@/pages/Market.vue'), children: [
|
{ path: '/market', component: () => import('@/pages/Market.vue'), children: [
|
||||||
{ path: '', redirect: '/market/scan' },
|
{ path: '', redirect: '/market/scan' },
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { RouterLink } from 'vue-router';
|
import { usePocketBase } from '@/pocketbase';
|
||||||
|
import { RouterLink, useRouter } from 'vue-router';
|
||||||
|
|
||||||
const links = [
|
const links = [
|
||||||
{ name: "Market", path: "/market" },
|
{ name: "Market", path: "/market" },
|
||||||
{ name: "Reprocess", path: "/reprocess" },
|
{ name: "Reprocess", path: "/reprocess" },
|
||||||
{ name: "Tools", path: "/tools" }
|
{ name: "Tools", path: "/tools" }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const pb = usePocketBase();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const logout = async () => {
|
||||||
|
pb.authStore.clear();
|
||||||
|
await router.push({ name: 'login' });
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<aside class="fixed top-0 left-0 w-64 h-screen transition-transform -translate-x-full sm:translate-x-0">
|
<aside class="fixed top-0 left-0 w-64 h-screen transition-transform -translate-x-full sm:translate-x-0">
|
||||||
<div class="h-full px-3 py-4 overflow-y-auto bg-slate-700">
|
<div class="h-full px-3 py-4 overflow-y-auto bg-slate-700 flex flex-col">
|
||||||
<ul class="space-y-2 font-medium">
|
<ul class="space-y-2 font-medium">
|
||||||
<li v-for="link in links" :key="link.name">
|
<li v-for="link in links" :key="link.name">
|
||||||
<RouterLink :to="link.path" class="flex items-center p-2 rounded-md hover:bg-slate-800">
|
<RouterLink :to="link.path" class="flex items-center p-2 rounded-md hover:bg-slate-800">
|
||||||
@@ -18,6 +27,9 @@ const links = [
|
|||||||
</RouterLink>
|
</RouterLink>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="mt-auto">
|
||||||
|
<button @click="logout">Logout</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ export default defineConfig(({ mode }) => {
|
|||||||
followRedirects: true,
|
followRedirects: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||||
},
|
},
|
||||||
|
'/pocketbase/': {
|
||||||
|
target: `https://${env.POCKET_BASE_URL}/`,
|
||||||
|
changeOrigin: true,
|
||||||
|
followRedirects: true,
|
||||||
|
rewrite: (path) => path.replace(/^\/pocketbase/, ''),
|
||||||
|
},
|
||||||
'/appraisal/': {
|
'/appraisal/': {
|
||||||
target: `https://${env.EVEPRAISAL_URL}/`,
|
target: `https://${env.EVEPRAISAL_URL}/`,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user