@page "/fcm-test" @inject IJSRuntime JSRuntime @attribute [Microsoft.AspNetCore.Authorization.AllowAnonymous]

FCM Token Test

Click the button below to request notification permission and generate your FCM token.

@if (!string.IsNullOrEmpty(Token)) {

Your Token:

Copy this token and use it to test your Backend API.

} @if (IsLoading) {

Requesting token...

} @if (!string.IsNullOrEmpty(ErrorMessage)) {

@ErrorMessage

}
@code { private string? Token { get; set; } private string? ErrorMessage { get; set; } private bool IsLoading { get; set; } private async Task GetToken() { IsLoading = true; ErrorMessage = null; try { Token = await JSRuntime.InvokeAsync("getFcmToken"); if (string.IsNullOrEmpty(Token)) { ErrorMessage = "Failed to get token. Check if you granted permission or if VAPID key is configured."; } } catch (Exception ex) { ErrorMessage = $"Error: {ex.Message}"; } finally { IsLoading = false; } } private async Task CopyToken() { if (!string.IsNullOrEmpty(Token)) { await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Token); await JSRuntime.InvokeVoidAsync("showToast", "Token copied to clipboard!", "success"); } } }