Merge branch 'beta' into 'main'
Beta See merge request fedeo/software!32
This commit is contained in:
@@ -4,25 +4,3 @@ services:
|
|||||||
web:
|
web:
|
||||||
image: reg.federspiel.software/fedeo/software:beta
|
image: reg.federspiel.software/fedeo/software:beta
|
||||||
restart: always
|
restart: always
|
||||||
# networks:
|
|
||||||
# - traefik
|
|
||||||
environment:
|
|
||||||
NUXT_PUBLIC_API_BASE: "https://backend.fedeo.io"
|
|
||||||
# labels:
|
|
||||||
# - "traefik.enable=true"
|
|
||||||
# - "traefik.docker.network=traefik"
|
|
||||||
# - "traefik.port=3000"
|
|
||||||
# # Middlewares
|
|
||||||
# - "traefik.http.middlewares.spaces-frontend-redirect-web-secure.redirectscheme.scheme=https"
|
|
||||||
# # Web Entrypoint
|
|
||||||
# - "traefik.http.routers.spaces-frontend.middlewares=spaces-frontend-redirect-web-secure"
|
|
||||||
# - "traefik.http.routers.spaces-frontend.rule=Host(`app.spaces.software`)"
|
|
||||||
# - "traefik.http.routers.spaces-frontend.entrypoints=web"
|
|
||||||
# # Web Secure Entrypoint
|
|
||||||
# - "traefik.http.routers.spaces-frontend-secure.rule=Host(`app.spaces.software`)"
|
|
||||||
# - "traefik.http.routers.spaces-frontend-secure.entrypoints=web-secured" #
|
|
||||||
# - "traefik.http.routers.spaces-frontend-secure.tls.certresolver=mytlschallenge"
|
|
||||||
|
|
||||||
#networks:
|
|
||||||
# traefik:
|
|
||||||
# external: true
|
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
export default defineNuxtPlugin(async () => {
|
export default defineNuxtPlugin(async () => {
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
await auth.init()
|
|
||||||
|
console.log("Auth init")
|
||||||
|
|
||||||
|
await auth.initStore()
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -11,41 +11,72 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
activeTenant: null as any,
|
activeTenant: null as any,
|
||||||
activeTenantData: null as any,
|
activeTenantData: null as any,
|
||||||
loading: true as boolean,
|
loading: true as boolean,
|
||||||
|
notLoggedIn: true,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async init(token) {
|
async persist(token) {
|
||||||
|
if(useCapacitor().getIsNative()) {
|
||||||
|
console.log("On Native")
|
||||||
|
await Preferences.set({
|
||||||
|
key:"token",
|
||||||
|
value: token,
|
||||||
|
})
|
||||||
|
useCookie("token").value = token // persistieren
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("On Web")
|
||||||
|
useCookie("token").value = token // persistieren
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async initStore() {
|
||||||
|
console.log("Auth initStore")
|
||||||
|
await this.fetchMe()
|
||||||
|
|
||||||
|
const tempStore = useTempStore()
|
||||||
|
|
||||||
|
if(this.profile.temp_config) tempStore.setStoredTempConfig(this.profile.temp_config)
|
||||||
|
if(this.activeTenant > 0) {
|
||||||
|
this.loading = false
|
||||||
|
if(useCapacitor().getIsNative()) {
|
||||||
|
navigateTo("/mobile")
|
||||||
|
} else {
|
||||||
|
navigateTo("/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async init(token=null) {
|
||||||
|
console.log("Auth init")
|
||||||
await this.fetchMe(token)
|
await this.fetchMe(token)
|
||||||
|
|
||||||
const tempStore = useTempStore()
|
const tempStore = useTempStore()
|
||||||
|
|
||||||
if(this.profile.temp_config) tempStore.setStoredTempConfig(this.profile.temp_config)
|
if(this.profile.temp_config) tempStore.setStoredTempConfig(this.profile.temp_config)
|
||||||
|
if(this.activeTenant > 0) {
|
||||||
if(useCapacitor().getIsNative()) {
|
this.loading = false
|
||||||
navigateTo("/mobile")
|
if(useCapacitor().getIsNative()) {
|
||||||
} else {
|
navigateTo("/mobile")
|
||||||
navigateTo("/")
|
} else {
|
||||||
|
navigateTo("/")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async login(email: string, password: string) {
|
async login(email: string, password: string) {
|
||||||
|
console.log("Auth login")
|
||||||
const { token } = await useNuxtApp().$api("/auth/login", {
|
const { token } = await useNuxtApp().$api("/auth/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: { email, password }
|
body: { email, password }
|
||||||
})
|
})
|
||||||
if(useCapacitor().getIsNative()) {
|
console.log(token)
|
||||||
await Preferences.set({
|
|
||||||
key:"token",
|
|
||||||
value: token,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
useCookie("token").value = token // persistieren
|
|
||||||
|
|
||||||
}
|
|
||||||
await this.fetchMe(token)
|
await this.fetchMe(token)
|
||||||
},
|
},
|
||||||
|
|
||||||
async logout() {
|
async logout() {
|
||||||
|
console.log("Auth logout")
|
||||||
try {
|
try {
|
||||||
await useNuxtApp().$api("/auth/logout", { method: "POST" })
|
await useNuxtApp().$api("/auth/logout", { method: "POST" })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -67,6 +98,7 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async fetchMe(jwt= null) {
|
async fetchMe(jwt= null) {
|
||||||
|
console.log("Auth fetchMe")
|
||||||
try {
|
try {
|
||||||
const me = await useNuxtApp().$api("/api/me", {
|
const me = await useNuxtApp().$api("/api/me", {
|
||||||
headers: { Authorization: `Bearer ${jwt}`,
|
headers: { Authorization: `Bearer ${jwt}`,
|
||||||
@@ -88,7 +120,6 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
if(me.activeTenant > 0) {
|
if(me.activeTenant > 0) {
|
||||||
this.activeTenant = me.activeTenant
|
this.activeTenant = me.activeTenant
|
||||||
this.activeTenantData = me.tenants.find(i => i.id === me.activeTenant)
|
this.activeTenantData = me.tenants.find(i => i.id === me.activeTenant)
|
||||||
this.loading = false
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -101,6 +132,7 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async switchTenant(tenant_id: string) {
|
async switchTenant(tenant_id: string) {
|
||||||
|
console.log("Auth switchTenant")
|
||||||
this.loading = true
|
this.loading = true
|
||||||
const res = await useNuxtApp().$api("/api/tenant/switch", {
|
const res = await useNuxtApp().$api("/api/tenant/switch", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -120,11 +152,6 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
|
|
||||||
}
|
}
|
||||||
await this.init(token)
|
await this.init(token)
|
||||||
if(useCapacitor().getIsNative()) {
|
|
||||||
navigateTo("/mobile")
|
|
||||||
} else {
|
|
||||||
navigateTo("/")
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hasPermission(key: string) {
|
hasPermission(key: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user