Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Не обновляется дата использования токена #436

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ coverage

/target
/Cargo.lock
/apps/web/build.zip
/apps/web/build.zip
1 change: 0 additions & 1 deletion apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ DATABASE_PORT=5432
DATABASE_NAME='databaseName'
DATABASE_USERNAME='user'
DATABASE_PASSWORD='password'
ENCRYPT_KEY='MySuperPassword!MySuperPassword!'

POSTGRES_USER=postgres
POSTGRES_PW=postgres
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/helpers/getCookieFromToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { API_ERRORS, ApiError } from '@api'
import type { DiaryUserId, Nullable } from '@diary-spo/shared'
import type { Nullable } from '@diary-spo/shared'
import { formatDate } from '@utils'
import { caching } from 'cache-manager'
import { authSaveUseDate } from 'src/models/Auth/actions/save'
import { AuthModel, type AuthModelType } from '../models/Auth'
import { DiaryUserModel, type DiaryUserModelType } from '../models/DiaryUser'
import { GroupModel, type GroupModelType } from '../models/Group'
Expand Down Expand Up @@ -75,6 +77,9 @@ export const getCookieFromToken = async (
throw new ApiError(API_ERRORS.INVALID_TOKEN, 401)
}

if (diaryUserAuth.lastUsedDate !== formatDate(new Date()))
authSaveUseDate(token, new Date())

const user = diaryUserAuth.diaryUser
const spoId = user.group.spo.id

Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/models/Auth/actions/save/authSaveUseDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { formatDate } from '@utils'
import { AuthModel, IAuthModel } from '../../model'

export const authSaveUseDate = async (
token: string,
date: Date
): Promise<[affectedCount: number]> =>
AuthModel.update(
{
lastUsedDate: formatDate(date)
},
{
where: {
token
}
}
)
1 change: 1 addition & 0 deletions apps/api/src/models/Auth/actions/save/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './authSaveUseDate'
Binary file modified bun.lockb
Binary file not shown.
Loading