u
This commit is contained in:
@@ -3,6 +3,7 @@ using FrontOffice.Main.Utilities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
||||
namespace FrontOffice.Main.Shared;
|
||||
public partial class MainLayout
|
||||
@@ -16,6 +17,8 @@ public partial class MainLayout
|
||||
private string? _email;
|
||||
|
||||
[Inject] private ILocalStorageService LocalStorage { get; set; } = default!;
|
||||
[Inject] private AuthService AuthService { get; set; } = default!;
|
||||
[Inject] private AuthDialogService AuthDialogService { get; set; } = default!;
|
||||
|
||||
private void ToggleTheme() => _isDark = !_isDark;
|
||||
private void ToggleDrawer() => _drawerOpen = !_drawerOpen;
|
||||
@@ -36,21 +39,18 @@ public partial class MainLayout
|
||||
|
||||
private async Task CheckAuthStatus()
|
||||
{
|
||||
var token = await LocalStorage.GetItemAsync<string>(TokenStorageKey);
|
||||
_isAuthenticated = !string.IsNullOrWhiteSpace(token);
|
||||
_isAuthenticated = await AuthService.IsAuthenticatedAsync();
|
||||
}
|
||||
|
||||
private async Task OpenAuthDialog()
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<AuthDialog>("ورود به حساب کاربری");
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (!result.Canceled)
|
||||
await AuthDialogService.ShowAuthDialogAsync();
|
||||
await CheckAuthStatus();
|
||||
if (_isAuthenticated)
|
||||
{
|
||||
await CheckAuthStatus();
|
||||
Snackbar.Add(GlobalConstants.SuccessMsg, Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void NavigateToProfile()
|
||||
@@ -60,16 +60,8 @@ public partial class MainLayout
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
await LocalStorage.RemoveItemAsync(TokenStorageKey);
|
||||
await LocalStorage.RemoveItemAsync("auth:phone-number");
|
||||
await LocalStorage.RemoveItemAsync("auth:redirect");
|
||||
await LocalStorage.RemoveItemAsync("referral:code");
|
||||
|
||||
await AuthService.LogoutAsync();
|
||||
_isAuthenticated = false;
|
||||
Snackbar.Add("با موفقیت از حساب کاربری خارج شدید.", Severity.Success);
|
||||
StateHasChanged();
|
||||
|
||||
// Navigate to home page
|
||||
Navigation.NavigateTo(RouteConstants.Main.MainPage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user