source: iknow-api/Repository/Implementations/RefreshTokenRepository.cs@ 4e061d8

Last change on this file since 4e061d8 was 4e061d8, checked in by imbrsk <boris696boris@…>, 11 months ago

Implement refresh token functionality with associated services and repositories

  • Property mode set to 100644
File size: 1.0 KB
Line 
1using iknow_api.Models;
2using iknow_api.Data;
3using iknow_api.Models;
4using Microsoft.EntityFrameworkCore;
5using iknow_api.Services;
6using iknow_api.DTOs;
7
8namespace iknow_api.Repositories
9{
10 public class RefreshTokenRepository : IRefreshTokenRepository
11 {
12 private readonly AppDbContext _context;
13
14 public RefreshTokenRepository(AppDbContext context)
15 {
16 _context = context;
17 }
18
19 public async Task AddTokenAsync(RefreshToken refreshToken)
20 {
21 _context.RefreshToken.Add(refreshToken);
22 await _context.SaveChangesAsync();
23 }
24
25 public Task<bool> DeleteTokenAsync(string refreshTokenDto)
26 {
27 throw new NotImplementedException();
28 }
29
30
31 public async Task<bool> VerifyTokenAsync(VerifyRefreshTokenDto refreshTokenDto)
32 {
33 return await _context.RefreshToken
34 .AnyAsync(rt => rt.Token == refreshTokenDto.token && !rt.IsValid && rt.ExpiresAt > DateTime.UtcNow);
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.