Blazor & WASM in combination to get statistics from Spotify API for performing the song analysis. With separate microservices for auth, Spotify, user data tracking, and application, connected through gRPC with Polly.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. @page "/callback"
  2. @using GrpcShared.DTO
  3. @using GrpcShared.DTO.Db
  4. @using NemAnBlazor.Services.Interfaces
  5. @inject NavigationManager NavigationMgr
  6. @inject IAuthClientService AuthService
  7. @inject Blazored.LocalStorage.ILocalStorageService localStorage
  8. @inject IIdentityClientService identityService
  9. <PageTitle>Redirecting...</PageTitle>
  10. <p role="status">Loading...</p>
  11. @code {
  12. protected override async Task OnInitializedAsync()
  13. {
  14. string url = NavigationMgr.Uri;
  15. //code is the only parameter in the url
  16. string code = url.Split("=")[1];
  17. var response = await AuthService.GetAccessToken(new GrpcShared.DTO.Auth.TokenRequest { Code = code});
  18. //if (response.access_token == null) NavigationMgr.NavigateTo("/");
  19. //store access token in local storage
  20. //await localStorage.SetItemAsync("token", response.AccessToken);
  21. //await localStorage.SetItemAsync("refresh_token", response.RefreshToken);
  22. //UserResponse user = new();
  23. //await identityService.SaveUserAsync(new GrpcShared.DTO.Db.UserResponse());
  24. string userId = await localStorage.GetItemAsync<string>("user_info");
  25. if(userId == null)
  26. {
  27. VoidMessage userRes = await identityService.SaveUserAsync(new GrpcShared.DTO.Db.UserResponse { RefreshToken = response.RefreshToken , Token = response.AccessToken});
  28. if (userRes.InsertedId != null)
  29. await localStorage.SetItemAsync<string>("user_info", userRes.InsertedId);
  30. }
  31. //redirect to home
  32. NavigationMgr.NavigateTo("/home");
  33. }
  34. }