u
This commit is contained in:
@@ -41,20 +41,18 @@
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudHidden Breakpoint="Breakpoint.SmAndUp" Invert="true">
|
||||
@if (_isAuthenticated)
|
||||
{
|
||||
<MudMenu Icon="@Icons.Material.Filled.Person" Color="Color.Inherit" Size="Size.Medium">
|
||||
<MudMenuItem OnClick="NavigateToProfile">پروفایل</MudMenuItem>
|
||||
<MudDivider />
|
||||
<MudMenuItem OnClick="Logout">خروج از حساب</MudMenuItem>
|
||||
</MudMenu>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Inherit" OnClick="OpenAuthDialog">ورود</MudButton>
|
||||
}
|
||||
</MudHidden>
|
||||
@if (_isAuthenticated)
|
||||
{
|
||||
<MudMenu Icon="@Icons.Material.Filled.Person" Color="Color.Inherit" Size="Size.Medium">
|
||||
<MudMenuItem OnClick="NavigateToProfile">پروفایل</MudMenuItem>
|
||||
<MudDivider />
|
||||
<MudMenuItem OnClick="Logout">خروج از حساب</MudMenuItem>
|
||||
</MudMenu>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Login" Color="Color.Inherit" OnClick="OpenAuthDialog" />
|
||||
}
|
||||
|
||||
<MudIconButton OnClick="@ToggleTheme" Edge="Edge.End"
|
||||
Icon="@(_isDark ? Icons.Material.Filled.DarkMode : Icons.Material.Filled.LightMode)" />
|
||||
|
||||
@@ -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