Skip to content

Commit

Permalink
Check for valid session.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Dec 12, 2024
1 parent 62a8b29 commit 8cdd167
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ export async function getSession(req: NextApiRequestCollect): Promise<SessionDat
}
}

return { ...session, visitId: visitId };
return { ...session, visitId };
}
9 changes: 5 additions & 4 deletions src/pages/api/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
await useSession(req, res);

const session = req.session;

if (!session?.id) {
return;
}

const iat = Math.floor(new Date().getTime() / 1000);

// expire visitId after 30 minutes
Expand All @@ -111,10 +116,6 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {

session.iat = iat;

if (!session.websiteId) {
return;
}

if (type === COLLECTION_TYPE.event) {
// eslint-disable-next-line prefer-const
let [urlPath, urlQuery] = safeDecodeURI(url)?.split('?') || [];
Expand Down

0 comments on commit 8cdd167

Please sign in to comment.