mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 08:04:51 +00:00
update timestamp more efficiently
This commit is contained in:
parent
2dadda640b
commit
7039822740
@ -32,16 +32,21 @@ describe('API Token Auth Strategy', () => {
|
||||
'api-token': {
|
||||
getBy,
|
||||
hash,
|
||||
update,
|
||||
},
|
||||
},
|
||||
},
|
||||
query() {
|
||||
return { update };
|
||||
},
|
||||
};
|
||||
|
||||
const response = await apiTokenStrategy.authenticate(ctx);
|
||||
|
||||
expect(getBy).toHaveBeenCalledWith({ accessKey: 'api-token_tests-hashed-access-key' });
|
||||
expect(update).toHaveBeenCalledWith(apiToken.id, { lastUsedAt: expect.any(Date) });
|
||||
expect(update).toHaveBeenCalledWith({
|
||||
data: { lastUsedAt: expect.any(Date) },
|
||||
where: { id: apiToken.id },
|
||||
});
|
||||
expect(response).toStrictEqual({ authenticated: true, credentials: apiToken });
|
||||
});
|
||||
|
||||
|
||||
@ -52,9 +52,10 @@ const authenticate = async (ctx) => {
|
||||
}
|
||||
}
|
||||
|
||||
// update lastUsedAt
|
||||
await apiTokenService.update(apiToken.id, {
|
||||
lastUsedAt: currentDate,
|
||||
// update lastUsedAt async without waiting or worrying about result
|
||||
await strapi.query('admin::api-token').update({
|
||||
where: { id: apiToken.id },
|
||||
data: { lastUsedAt: currentDate },
|
||||
});
|
||||
|
||||
if (apiToken.type === constants.API_TOKEN_TYPE.CUSTOM) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user