Skip to content

Commit a08bdb4

Browse files
authored
Не обновляется дата использования токена (#436)
1 parent 7b900ab commit a08bdb4

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ coverage
4141

4242
/target
4343
/Cargo.lock
44-
/apps/web/build.zip
44+
/apps/web/build.zip

apps/api/.env.example

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ DATABASE_PORT=5432
1212
DATABASE_NAME='databaseName'
1313
DATABASE_USERNAME='user'
1414
DATABASE_PASSWORD='password'
15-
ENCRYPT_KEY='MySuperPassword!MySuperPassword!'
1615

1716
POSTGRES_USER=postgres
1817
POSTGRES_PW=postgres

apps/api/src/helpers/getCookieFromToken.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { API_ERRORS, ApiError } from '@api'
2-
import type { DiaryUserId, Nullable } from '@diary-spo/shared'
2+
import type { Nullable } from '@diary-spo/shared'
3+
import { formatDate } from '@utils'
34
import { caching } from 'cache-manager'
5+
import { authSaveUseDate } from 'src/models/Auth/actions/save'
46
import { AuthModel, type AuthModelType } from '../models/Auth'
57
import { DiaryUserModel, type DiaryUserModelType } from '../models/DiaryUser'
68
import { GroupModel, type GroupModelType } from '../models/Group'
@@ -75,6 +77,9 @@ export const getCookieFromToken = async (
7577
throw new ApiError(API_ERRORS.INVALID_TOKEN, 401)
7678
}
7779

80+
if (diaryUserAuth.lastUsedDate !== formatDate(new Date()))
81+
authSaveUseDate(token, new Date())
82+
7883
const user = diaryUserAuth.diaryUser
7984
const spoId = user.group.spo.id
8085

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { formatDate } from '@utils'
2+
import { AuthModel, IAuthModel } from '../../model'
3+
4+
export const authSaveUseDate = async (
5+
token: string,
6+
date: Date
7+
): Promise<[affectedCount: number]> =>
8+
AuthModel.update(
9+
{
10+
lastUsedDate: formatDate(date)
11+
},
12+
{
13+
where: {
14+
token
15+
}
16+
}
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './authSaveUseDate'

bun.lockb

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)