From aac79776209d8e7289b163eb282c142e5aa0c4e8 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 13 Apr 2026 23:12:00 +0200 Subject: [PATCH] Correction du demarrage apres la modal d'authentification --- ChessCubing.App/Components/SiteMenu.razor | 48 +++++++++++++--------- ChessCubing.App/Pages/Authentication.razor | 9 +++- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ChessCubing.App/Components/SiteMenu.razor b/ChessCubing.App/Components/SiteMenu.razor index d7141be..4b956ae 100644 --- a/ChessCubing.App/Components/SiteMenu.razor +++ b/ChessCubing.App/Components/SiteMenu.razor @@ -140,26 +140,15 @@ => user.FindFirst("email")?.Value ?? "Session active"; - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (!firstRender) - { - return; - } - - _dotNetReference = DotNetObjectReference.Create(this); - await JS.InvokeVoidAsync("chesscubingAuthModal.registerListener", _dotNetReference); - _listenerRegistered = true; - } - - private void OpenLoginModal() - => OpenAuthModal("Se connecter", LoginHref); - - private void OpenRegisterModal() - => OpenAuthModal("Creer un compte", RegisterHref); - - private void OpenAuthModal(string title, string source) + private async Task OpenLoginModal() + => await OpenAuthModalAsync("Se connecter", LoginHref); + + private async Task OpenRegisterModal() + => await OpenAuthModalAsync("Creer un compte", RegisterHref); + + private async Task OpenAuthModalAsync(string title, string source) { + await EnsureAuthListenerAsync(); AuthModalTitle = title; AuthModalSource = source; ShowAuthModal = true; @@ -171,6 +160,27 @@ AuthModalSource = null; } + private async Task EnsureAuthListenerAsync() + { + if (_listenerRegistered) + { + return; + } + + _dotNetReference ??= DotNetObjectReference.Create(this); + + try + { + await JS.InvokeVoidAsync("chesscubingAuthModal.registerListener", _dotNetReference); + _listenerRegistered = true; + } + catch + { + // Si le navigateur garde encore un ancien script en cache, + // on laisse l'application fonctionner et la modal reste utilisable sans auto-fermeture. + } + } + [JSInvokable] public Task HandleAuthModalMessage(string status) { diff --git a/ChessCubing.App/Pages/Authentication.razor b/ChessCubing.App/Pages/Authentication.razor index 1422a05..7a040a1 100644 --- a/ChessCubing.App/Pages/Authentication.razor +++ b/ChessCubing.App/Pages/Authentication.razor @@ -66,7 +66,14 @@ } await Task.Delay(700); - await JS.InvokeVoidAsync("chesscubingAuthModal.notifyParent", status); + + try + { + await JS.InvokeVoidAsync("chesscubingAuthModal.notifyParent", status); + } + catch + { + } } private static string NormalizeReturnUrl(string? returnUrl)