Added Frontend
This commit is contained in:
35
frontend/plugins/api.ts
Normal file
35
frontend/plugins/api.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {Preferences} from "@capacitor/preferences";
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const api = $fetch.create({
|
||||
baseURL: config.public.apiBase,
|
||||
credentials: "include",
|
||||
async onRequest({options}) {
|
||||
// Token aus Cookie holen
|
||||
let token: string | null | undefined = ""
|
||||
if (useCapacitor().getIsNative()) {
|
||||
const {value} = await Preferences.get({key: 'token'});
|
||||
token = value
|
||||
} else {
|
||||
token = useCookie("token").value
|
||||
}
|
||||
|
||||
|
||||
// Falls im Request explizit ein anderer JWT übergeben wird → diesen verwenden
|
||||
if (options.context && (options.context as any).jwt) {
|
||||
token = (options.context as any).jwt
|
||||
}
|
||||
|
||||
if (token) {
|
||||
options.headers = {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return { provide: { api } }
|
||||
})
|
||||
9
frontend/plugins/auth-init.client.ts
Normal file
9
frontend/plugins/auth-init.client.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export default defineNuxtPlugin(async () => {
|
||||
const auth = useAuthStore()
|
||||
|
||||
console.log("Auth init")
|
||||
|
||||
await auth.initStore()
|
||||
|
||||
|
||||
})
|
||||
4
frontend/plugins/chartjs.ts
Normal file
4
frontend/plugins/chartjs.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Chart, Title, Tooltip, Legend, LineElement, CategoryScale, LinearScale, PointElement } from 'chart.js'
|
||||
export default defineNuxtPlugin(() => {
|
||||
Chart.register(CategoryScale, LinearScale, LineElement, Title, Tooltip, Legend, PointElement)
|
||||
})
|
||||
14
frontend/plugins/dayjs.ts
Normal file
14
frontend/plugins/dayjs.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import dayjs from 'dayjs'
|
||||
import duration from 'dayjs/plugin/duration'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import localizedFormat from 'dayjs/plugin/localizedFormat'
|
||||
import 'dayjs/locale/de'
|
||||
|
||||
dayjs.extend(duration)
|
||||
dayjs.extend(relativeTime)
|
||||
dayjs.extend(localizedFormat)
|
||||
dayjs.locale('de')
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
return { provide: { dayjs } }
|
||||
})
|
||||
5
frontend/plugins/vue-draggable.client.js
Normal file
5
frontend/plugins/vue-draggable.client.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import draggable from 'vuedraggable'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.vueApp.component('draggable', draggable);
|
||||
})
|
||||
Reference in New Issue
Block a user