-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserUseCase.cs
More file actions
42 lines (36 loc) · 1.34 KB
/
Copy pathUserUseCase.cs
File metadata and controls
42 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ProjectX.Server.Database.SocialIdentity;
using ProjectX.Server.Database.User;
using ProjectX.Server.Firebase;
using ProjectX.Server.Model.SocialIdentity;
namespace ProjectX.Server.UseCase;
public class UserUseCase(
ILogger<UserUseCase> logger,
IUserRepository userRepository,
ISocialIdentityRepository socialIdentityRepository,
FirebaseService firebaseService
) : IUserUseCase
{
public async Task<UserModel?> LoginByFirebase(string token)
{
var socialUser = await firebaseService.GetUserInfo(token);
if (socialUser == null)
{
throw new Exception("Invalid firebase token");
}
var user = await userRepository.FindByUid(socialUser.Uid);
if (user == null)
{
user = await userRepository.CreateModel(socialUser.FirstName, socialUser.LastName, socialUser.Phone, socialUser.AvatarUrl, DateTime.Now);
var socialType = SocialType.Google;
if (socialUser.FirebaseProvider.FirebaseProviderType == FirebaseProviderType.EmailPassword)
{
socialType = SocialType.EmailPassword;
}
await socialIdentityRepository.Create(user.Id, socialUser.Uid, socialType, DateTime.Now);
}
return user;
}
}