Skip to content

Commit

Permalink
Fixed visit logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Jan 31, 2025
1 parent aaf8b19 commit edd72cd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/api/send/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ export async function POST(request: Request) {
}

// Visit info
const now = Math.floor(new Date().getTime() / 1000);
let visitId = cache?.visitId || uuid(sessionId, visitSalt());
const iat = Math.floor(new Date().getTime() / 1000);
let iat = cache?.iat || now;

// Expire visit after 30 minutes
if (cache?.iat && iat - cache?.iat > 1800) {
if (now - iat > 1800) {
visitId = uuid(sessionId, visitSalt());
iat = now;
}

if (type === COLLECTION_TYPE.event) {
Expand Down Expand Up @@ -187,5 +189,5 @@ export async function POST(request: Request) {

const token = createToken({ websiteId, sessionId, visitId, iat }, secret());

return json(token);
return json({ cache: token });
}

0 comments on commit edd72cd

Please sign in to comment.