Skip to content

Commit 2a9cc5e

Browse files
committed
Добавить обновление даты последнего использования токена при его извлечении
1 parent 7b900ab commit 2a9cc5e

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ coverage
4242
/target
4343
/Cargo.lock
4444
/apps/web/build.zip
45+
bun.lockb

apps/api/.env.example

Lines changed: 0 additions & 1 deletion
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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { API_ERRORS, ApiError } from '@api'
2-
import type { DiaryUserId, Nullable } from '@diary-spo/shared'
2+
import type { Nullable } from '@diary-spo/shared'
33
import { caching } from 'cache-manager'
44
import { AuthModel, type AuthModelType } from '../models/Auth'
55
import { DiaryUserModel, type DiaryUserModelType } from '../models/DiaryUser'
66
import { GroupModel, type GroupModelType } from '../models/Group'
77
import { SPOModel, type SPOModelType } from '../models/SPO'
8+
import { formatDate } from '@utils'
9+
import { authSaveUseDate } from 'src/models/Auth/actions/save'
810

911
const memoryCache = await caching('memory', {
1012
max: 1000,
@@ -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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
lastUsedDate: formatDate(date)
10+
},
11+
{
12+
where: {
13+
token
14+
}
15+
})
Lines changed: 1 addition & 0 deletions
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)