Skip to content

Commit ed73bdf

Browse files
Merge #1502
1502: Fixes the expiresAt UNIX timestamp used for tenant token generation from miliseconds to seconds r=bidoubiwa a=roy9495 # Pull Request ## Related issue Fixes #1495 ## What does this PR do? - In src/token.ts changes this function exp: expiresAt?.getTime() such that its output changes from milliseconds to unixtime ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: TATHAGATA ROY <[email protected]>
2 parents dae1c5a + 2dd7c20 commit ed73bdf

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function createPayload(payloadParams: {
112112
const payload = {
113113
searchRules,
114114
apiKeyUid: uid,
115-
exp: expiresAt?.getTime(),
115+
exp: expiresAt ? Math.floor(expiresAt.getTime() / 1000) : undefined,
116116
}
117117

118118
return encode64(payload).replace(/=/g, '')

tests/token.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ describe.each([{ permission: 'Admin' }])(
160160
const [_, payload] = token.split('.')
161161
const searchClient = new MeiliSearch({ host: HOST, apiKey: token })
162162

163-
expect(JSON.parse(decode64(payload)).exp).toEqual(date.getTime())
163+
expect(JSON.parse(decode64(payload)).exp).toEqual(
164+
Math.floor(date.getTime() / 1000)
165+
)
164166
expect(searchClient.index(UID).search()).resolves.not.toBeUndefined()
165167
})
166168

0 commit comments

Comments
 (0)