diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f111e8d..eec8357 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,10 +4,13 @@
-
+
+
-
+
+
+
@@ -266,7 +269,7 @@
-
+
@@ -508,7 +511,15 @@
1769098182184
-
+
+
+ 1769098861988
+
+
+
+ 1769098861988
+
+
@@ -558,7 +569,6 @@
-
@@ -583,7 +593,8 @@
-
+
+
diff --git a/README.md b/README.md
index 8d0bb01..9835150 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ Vérifier que dans le .env.local, vous avez :
* JWT_SECRET_KEY (à générer avec la commande php bin/console lexik:jwt:generate-keypair)
* JWT_PUBLIC_KEY
* JWT_PASSPHRASE (à généré dans le conteneur avec la commande php -r "echo bin2hex(random_bytes(32));")
-* COOKIE_SECURE=0 (en dev 0 et en prod 1)
+* COOKIE_SECURE=0 (en dev 0 et en prod 1. Si c'est du http, laisser en 0)
Vérifier que dans le .env du dossier frontend, vous avez :
* NUXT_PUBLIC_API_BASE="http://localhost:8080/api"
@@ -120,9 +120,3 @@ VALUES ('Mon user', '["ROLE_USER"]', 'Mon mdp hashé');
Pour suivre les logs en temps réel :
* tail -f var/log/dev.log
* tail -f var/log/prod.log
-
-
-sudo usermod -aG www-data malio
-sudo chown -R malio:www-data /var/www/ferme
-sudo chmod -R g+rwX /var/www/ferme/var
-sudo chmod -R g+rx /var/www/ferme
diff --git a/frontend/composables/useApi.ts b/frontend/composables/useApi.ts
index 7b00b35..0d5b79a 100644
--- a/frontend/composables/useApi.ts
+++ b/frontend/composables/useApi.ts
@@ -29,6 +29,7 @@ export const useApi = (): ApiClient => {
const toast = useToast()
const auth = useAuthStore()
const nuxtApp = useNuxtApp()
+ let isHandlingUnauthorized = false
const i18n = nuxtApp.$i18n as
| {
t: (key: string) => string
@@ -95,7 +96,23 @@ export const useApi = (): ApiClient => {
})
}
},
- onResponseError({ response, error, options }) {
+ async onResponseError({ response, error, options }) {
+ if (response?.status === 401) {
+ const requestUrl = typeof options?.url === 'string' ? options.url : ''
+ if (!requestUrl.includes('login_check') && !requestUrl.includes('logout')) {
+ if (!isHandlingUnauthorized) {
+ isHandlingUnauthorized = true
+ auth.clearSession()
+ const route = useRoute()
+ if (route.path !== '/login') {
+ await navigateTo('/login')
+ }
+ isHandlingUnauthorized = false
+ }
+ }
+ return
+ }
+
const apiOptions = options as ApiFetchOptions<'json'>
if (apiOptions?.toast === false) {
return
diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts
index bcf2881..fb70f39 100644
--- a/frontend/nuxt.config.ts
+++ b/frontend/nuxt.config.ts
@@ -19,7 +19,7 @@ export default defineNuxtConfig({
},
toast: {
settings: {
- timeout: 0,
+ timeout: 10000,
closeOnClick: true,
progressBar: false
}
diff --git a/frontend/stores/auth.ts b/frontend/stores/auth.ts
index f33a8e3..42ecfa4 100644
--- a/frontend/stores/auth.ts
+++ b/frontend/stores/auth.ts
@@ -12,6 +12,11 @@ export const useAuthStore = defineStore('auth', {
isAuthenticated: (state) => Boolean(state.user)
},
actions: {
+ clearSession() {
+ this.user = null
+ this.checked = true
+ this.isLoading = false
+ },
async ensureSession() {
if (this.checked) {
return this.user