New Backend changes

This commit is contained in:
2025-08-31 18:28:59 +02:00
parent b0497142ed
commit 6d76acc0bc
26 changed files with 813 additions and 1379 deletions

24
plugins/api.ts Normal file
View File

@@ -0,0 +1,24 @@
export default defineNuxtPlugin(() => {
const api = $fetch.create({
baseURL: "http://localhost:3100",
credentials: "include",
onRequest({ options }) {
// Token aus Cookie holen
let 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 } }
})