Skip to content

Commit 1569fc8

Browse files
committed
refactor: simplify created_at timestamp conversion using date-fns
1 parent f2f668c commit 1569fc8

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/routes/integrations/intercom.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FastifyInstance } from 'fastify';
22
import jwt from 'jsonwebtoken';
33
import createOrGetConnection from '../../db';
44
import { User } from '../../entity';
5+
import { getUnixTime } from 'date-fns';
56

67
export default async function (fastify: FastifyInstance): Promise<void> {
78
const con = await createOrGetConnection();
@@ -40,10 +41,7 @@ export default async function (fastify: FastifyInstance): Promise<void> {
4041
}
4142

4243
if (user.createdAt) {
43-
// Intercom expects created_at as Unix timestamp (seconds)
44-
payload.created_at = Math.floor(
45-
new Date(user.createdAt).getTime() / 1000,
46-
);
44+
payload.created_at = getUnixTime(user.createdAt);
4745
}
4846

4947
// Sign with HS256 and short expiry (10 minutes recommended minimum)

0 commit comments

Comments
 (0)