fix(portal): add invitation links and correct customer login routing
This commit is contained in:
@@ -31,6 +31,11 @@ export const useAuthStore = defineStore("auth", {
|
||||
}),
|
||||
|
||||
actions: {
|
||||
getLandingPath() {
|
||||
if (this.user?.must_change_password) return "/password-change"
|
||||
return this.profile?.customer_for_portal ? "/customer-portal" : "/"
|
||||
},
|
||||
|
||||
tokenCookie() {
|
||||
return useCookie<string | null>("token", { path: "/" })
|
||||
},
|
||||
@@ -265,14 +270,14 @@ export const useAuthStore = defineStore("auth", {
|
||||
const tempStore = useTempStore()
|
||||
|
||||
if(this.profile?.temp_config) tempStore.setStoredTempConfig(this.profile.temp_config)
|
||||
this.loading = false
|
||||
if(this.activeTenant > 0) {
|
||||
this.loading = false
|
||||
|
||||
navigateTo("/")
|
||||
return navigateTo(this.getLandingPath())
|
||||
}
|
||||
},
|
||||
|
||||
async login(email: string, password: string, rememberMe = false) {
|
||||
this.loading = true
|
||||
try {
|
||||
console.log("Auth login")
|
||||
const { token, refreshToken } = await useNuxtApp().$api("/auth/login", {
|
||||
@@ -289,21 +294,15 @@ export const useAuthStore = defineStore("auth", {
|
||||
await this.fetchMe(token)
|
||||
|
||||
|
||||
// 3. WICHTIG: Jetzt explizit weiterleiten!
|
||||
// Prüfen, ob der User geladen wurde
|
||||
if (this.user) {
|
||||
// Falls Passwort-Änderung erzwungen wird (passend zu deiner Middleware)
|
||||
if (this.user.must_change_password) {
|
||||
return navigateTo("/password-change")
|
||||
}
|
||||
|
||||
// Normaler Login -> Dashboard
|
||||
return navigateTo("/")
|
||||
}
|
||||
if (!this.user) throw new Error("Die Sitzung konnte nicht geladen werden.")
|
||||
this.loading = false
|
||||
return await navigateTo(this.getLandingPath(), { replace: true })
|
||||
|
||||
} catch (e) {
|
||||
console.log("login error:" + e)
|
||||
throw e
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user