Skip to content

Commit

Permalink
fix: use dayjs
Browse files Browse the repository at this point in the history
mgramigna committed Dec 16, 2023
1 parent 987b770 commit 6f43e9f
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
"@trpc/next": "next",
"@trpc/react-query": "next",
"@trpc/server": "next",
"date-fns": "^2.30.0",
"dayjs": "^1.11.10",
"next": "^14.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
3 changes: 2 additions & 1 deletion apps/nextjs/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type NextRequest } from 'next/server';
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { addSeconds } from 'date-fns';
import dayjs from 'dayjs';

import { appRouter, createTRPCContext } from '@canvas-challenge/api';
import { getAuthToken } from '@canvas-challenge/canvas';
@@ -48,7 +49,7 @@ const handler = async (req: NextRequest) => {

token = entry.token;

const isExpired = addSeconds(entry.created, entry.expiresInSeconds) < new Date();
const isExpired = dayjs(entry.created).add(entry.expiresInSeconds, 'seconds') < dayjs();

if (isExpired) {
token = await getNewAccessToken();
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f43e9f

Please sign in to comment.