Skip to content

Commit 88f052f

Browse files
committed
fix register
1 parent 9a4c519 commit 88f052f

5 files changed

Lines changed: 11 additions & 13 deletions

File tree

CodeWorks.Auth.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77

88
<PackageId>CodeWorks.Auth</PackageId>
9-
<Version>0.0.8</Version>
9+
<Version>0.0.9</Version>
1010
<Authors>CodeWorks</Authors>
1111
<Company>CodeWorks</Company>
1212
<Description>Flexible, pluggable authentication module for .NET APIs with JWT, email login, and MFA support.</Description>

Interfaces/IAccountIdentityStore.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ public interface IAccountIdentityStore<TIdentity> where TIdentity : IAccountIden
44
{
55
Task<TIdentity> FindByEmailAsync(string email);
66
Task<bool> EmailExistsAsync(string email);
7-
Task SaveAsync(TIdentity user);
7+
Task<TIdentity> UpdateAsync(TIdentity user);
88
Task<TIdentity> FindByIdAsync(string id);
9-
109
Task<TIdentity> FindByProviderAsync(string provider, string providerId);
11-
12-
Task CreateAsync(TIdentity user);
10+
Task<TIdentity> CreateAsync(TIdentity user);
1311
Task DeleteAsync(string id);
1412

1513

@@ -18,7 +16,7 @@ async public Task<TIdentity> MarkEmailVerifiedAsync(TIdentity user)
1816
{
1917
if (user == null) throw new ArgumentNullException(nameof(user));
2018
user.IsEmailVerified = true;
21-
await SaveAsync(user);
19+
await UpdateAsync(user);
2220
return user;
2321
}
2422

Services/AuthService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ public class AuthService<TIdentity>(IAccountIdentityStore<TIdentity> store, IJwt
1111
private readonly IAccountIdentityStore<TIdentity> _store = store;
1212
private readonly IJwtService _jwt = jwt;
1313

14-
public async Task<AuthResult<TIdentity>> RegisterAsync(TIdentity user, string password)
14+
public async Task<AuthResult<TIdentity>> RegisterAsync(TIdentity userData, string password)
1515
{
16-
if (await _store.EmailExistsAsync(user.Email))
16+
if (await _store.EmailExistsAsync(userData.Email))
1717
return AuthResult<TIdentity>.Failure("Email already registered.");
1818

19-
user.PasswordHash = PasswordHelper<TIdentity>.HashPassword(user, password);
20-
await _store.SaveAsync(user);
19+
userData.PasswordHash = PasswordHelper<TIdentity>.HashPassword(userData, password);
20+
var user = await _store.CreateAsync(userData);
2121
return AuthResult<TIdentity>.Success(user, _jwt.GenerateToken(user));
2222
}
2323

@@ -41,7 +41,7 @@ public async Task<AuthResult<TIdentity>> ResetPasswordAsync(string email, string
4141
return AuthResult<TIdentity>.Failure("User not found.");
4242

4343
user.PasswordHash = PasswordHelper<TIdentity>.HashPassword(user, newPassword);
44-
await _store.SaveAsync(user);
44+
await _store.UpdateAsync(user);
4545
return AuthResult<TIdentity>.Success(user, _jwt.GenerateToken(user));
4646
}
4747

Services/EmailAuthService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public async Task<bool> ResetPasswordAsync(string token, string newPassword)
131131

132132
user.PasswordHash = PasswordHelper<IAccountIdentity>.HashPassword(user, newPassword);
133133
user.IsEmailVerified = true;
134-
await _userStore.SaveAsync(user);
134+
await _userStore.UpdateAsync(user);
135135
await _tokenStore.MarkTokenUsedAsync(token);
136136
return true;
137137
}

Services/OAuthService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public async Task<AuthResult<TIdentity>> HandleOAuthCallbackAsync(ExternalLoginI
116116
existingUser.ProfilePictureUrl = picture;
117117
}
118118

119-
await _userStore.SaveAsync(existingUser);
119+
await _userStore.UpdateAsync(existingUser);
120120

121121
var token = _authService.GenerateAuthToken(existingUser);
122122
return AuthResult<TIdentity>.Success(existingUser, token.Token!);

0 commit comments

Comments
 (0)