File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22using cubets_core . Modules . Auth . DTOs ;
33using cubets_core . Modules . Auth . Models ;
44using cubets_core . Modules . Auth . Services ;
5+ using CubetsCore . Modules . Auth . DTOs ;
56using Microsoft . AspNetCore . Mvc ;
67using Microsoft . EntityFrameworkCore ;
78
@@ -39,5 +40,13 @@ public async Task<IActionResult> Guest()
3940 var result = await _authService . GuestLoginAsync ( ) ;
4041 return Ok ( _response . Success ( result , "Login as Guest Successful!" ) ) ;
4142 }
43+
44+ [ HttpDelete ( "logout" ) ]
45+ public async Task < IActionResult > Logout ( [ FromBody ] RevokedTokenRequestDto dto )
46+ {
47+ var result = await _authService . LogoutAsync ( dto ) ;
48+ return Ok ( _response . Success ( result , "Anda berhasil keluar!" ) ) ;
49+ }
50+
4251 }
4352}
Original file line number Diff line number Diff line change 1+ namespace CubetsCore . Modules . Auth . DTOs
2+ {
3+ public class LogoutResponseDto
4+ {
5+ public bool Success { get ; set ; }
6+ public string ? Message { get ; set ; }
7+ }
8+ }
Original file line number Diff line number Diff line change 1+ namespace CubetsCore . Modules . Auth . DTOs
2+ {
3+ public class RevokedTokenRequestDto
4+ {
5+ public string ? Token { get ; }
6+ }
7+ }
Original file line number Diff line number Diff line change 11using cubets_core . Helpers ;
22using cubets_core . Modules . Auth . DTOs ;
33using cubets_core . Modules . Auth . Models ;
4+ using CubetsCore . Modules . Auth . DTOs ;
5+ using CubetsCore . Modules . Auth . Models ;
46using Microsoft . EntityFrameworkCore ;
57using System . Security . Cryptography ;
68using System . Text ;
@@ -97,6 +99,27 @@ public async Task<AuthResponseDto> GuestLoginAsync()
9799 } ;
98100 }
99101
102+ public async Task < LogoutResponseDto > LogoutAsync ( RevokedTokenRequestDto dto )
103+ {
104+ if ( string . IsNullOrWhiteSpace ( dto . Token ) )
105+ throw new Exception ( "Token diperlukan!" ) ;
106+
107+ _dbContext . RevokedTokens . Add ( new RevokedToken
108+ {
109+ Token = dto . Token ,
110+ RevokedAt = DateTime . UtcNow
111+ } ) ;
112+
113+ await _dbContext . SaveChangesAsync ( ) ;
114+
115+ return new LogoutResponseDto
116+ {
117+ Success = true ,
118+ Message = "Logout berhasil."
119+ } ;
120+ }
121+
122+
100123 private string HashPassword ( string password )
101124 {
102125 using var sha = SHA256 . Create ( ) ;
Original file line number Diff line number Diff line change 11using cubets_core . Modules . Auth . DTOs ;
2+ using CubetsCore . Modules . Auth . DTOs ;
23
34namespace cubets_core . Modules . Auth . Services
45{
@@ -7,5 +8,7 @@ public interface IAuthService
78 Task < AuthResponseDto > RegisterAsync ( RegisterRequestDto dto ) ;
89 Task < AuthResponseDto > LoginAsync ( LoginRequestDto dto ) ;
910 Task < AuthResponseDto > GuestLoginAsync ( ) ;
11+
12+ Task < LogoutResponseDto > LogoutAsync ( RevokedTokenRequestDto dto ) ;
1013 }
1114}
You can’t perform that action at this time.
0 commit comments