gigafibre-fsm/apps/ops/src/stores/auth.js
louispaulb e6ac8b11ef fix(ops): fail-loud when OPS perms don't load + username fallback (supersede 96da97b session overlay)
Root cause of the recurring "blank menu": the hub keys OPS permissions to the
exact Authentik email (louis@targo.ca). If whoami passes a different email
(duplicate account e.g. louism@targointernet.com) or an empty email, the hub
404s → can()=false → menu/search/avis silently blank, mistaken for a token bug.
The ERP token and Authentik provider config were verified correct throughout.

- REVERT the misleading session-fix (96da97b): drop verifySessionAlive /
  sessionExpired / auto-reload churn and the "Session expirée" overlay; restore
  the original keep-alive ping. (Re-login couldn't fix a perms/identity issue,
  so that overlay only added noise.)
- FAIL-LOUD (App.vue): when permissions don't load in prod, show a clear overlay
  naming the exact account OPS received ("OPS a reçu <email>, pas de permissions")
  + Changer de compte / Recharger — instead of a silent blank shell.
- USERNAME FALLBACK: whoami username is captured (api/auth getAuthUsername),
  passed to loadPermissions, and the hub (/auth/permissions) retries by username
  when the email matches no provisioned OPS account. Verified on prod: username=Louis
  alone resolves; bad-email+username falls back; unknown → 404.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 16:49:26 -04:00

28 lines
1006 B
JavaScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getLoggedUser, logout, getAuthUsername } from 'src/api/auth'
import { usePermissions } from 'src/composables/usePermissions'
export const useAuthStore = defineStore('auth', () => {
const user = ref(null)
const loading = ref(true)
const { loadPermissions } = usePermissions()
async function checkSession () {
loading.value = true
try {
user.value = await getLoggedUser()
// Permissions depuis le hub : par courriel, avec REPLI par username Authentik (whoami sans courriel /
// courriel non provisionné). Si les deux sont vides → permissions non chargées → App.vue affiche « fail-loud ».
const email = (user.value && user.value !== 'authenticated') ? user.value : ''
await loadPermissions(email, getAuthUsername())
} catch {
user.value = 'authenticated'
} finally {
loading.value = false
}
}
return { user, loading, checkSession, doLogout: logout }
})