Skip to content

Commit 7f336bc

Browse files
committed
Merge branch main into antti/add-tanstack-library
2 parents 616d940 + 71ddbc5 commit 7f336bc

File tree

8 files changed

+79
-8
lines changed

8 files changed

+79
-8
lines changed

.env.example

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ GOOGLE_SERVICE_ACCOUNT_JSON_FILE="google_service_account-arctic-diode-438812-b5-
1212

1313

1414
# This variable is mostly used for deployable apps such as Vercel, Heroku app, etc
15+
# Note: Vercel env variables cannot contain newlines, so you need to remove them from the JSON object
16+
# Note: Vercel expects bare string without quotes around the string
1517
# If GOOGLE_SERVICE_ACCOUNT_JSON_FILE and GOOGLE_SERVICE_ACCOUNT_CREDENTIALS are defined, GOOGLE_SERVICE_ACCOUNT_CREDENTIALS will take the priority
1618
# Add into this variable the whole object inside Service Account's JSON file.
1719
# Should look something like this:
@@ -26,4 +28,9 @@ GOOGLE_SERVICE_ACCOUNT_CREDENTIALS=`{
2628
"token_uri": "https://accounts.google.com/o/oauth2/token",
2729
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
2830
"client_x509_cert_url": "your-cert-url"
29-
}`
31+
}`
32+
33+
# This is used in Vercel to secure the Cron Job API endpoint
34+
# Vercel recommends to have a password with at least 16 characters
35+
# More details: https://vercel.com/docs/cron-jobs/manage-cron-jobs#securing-cron-jobs
36+
CRON_SECRET="secretPasswordHere"

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ After making these changes, save the `.env` file.
128128

129129
## Troubleshooting Errors
130130

131-
**Error: `dotenv: not found`**
131+
### Error: `dotenv: not found`
132132

133133
- Ensure you've installed the `dotenv-cli` package. It's usually installed with other dependencies when using `npm i`. If not, use:
134134

@@ -143,3 +143,19 @@ npm install -g dotenv-cli
143143
```
144144

145145
**Note:** You might need root access for global installation on Linux.
146+
147+
### Error while running SVGR (npm run svgr)
148+
149+
If you get this following error while running `npm run svgr`:
150+
151+
```
152+
Failed to handle file: public/images/icons/contact-details.svg # NOTE, this is just an example .svg file
153+
/lahjalista/node_modules/@svgr/cli/dist/index.js:435
154+
throw error;
155+
^
156+
157+
Error [ERR_REQUIRE_ESM]: require() of ES Module /lahjalista/node_modules/prettier-plugin-tailwindcss/dist/index.mjs not supported.
158+
Instead change the require of /lahjalista/node_modules/prettier-plugin-tailwindcss/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.
159+
```
160+
161+
Head to `.prettierrc`file and remove the following line:`"plugins": ["prettier-plugin-tailwindcss"]`. Save the `.prettierrc`and try to run`npm run svgr` again. Now it should work. Remember to add the removed line back.

TODO.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
# jos: sähköposti ei ole sääntöjen mukainen && salasanan pituus <= 0 -> Kirjaudu-buttonin className="cursor-not-allowed hover:text-white"
66

7-
# Rekistöröidessä kun rekistöröidy-painike on painettu -> tee napista semmoinen ettei voi painaa uudelleen / tee jonkinlainen latausindikaattori jotta käyttäjä tietää, että jotain tapahtuu. Tämä "ongelma" näkyy parhaiten Vercelin tarjoamassa testiympäristössä, jossa nopeudet eivät ole localhostin kaltaiset
8-
97
# Ehkä jonkinlainen kysymys, että haluaako pysyä kirjautuneena kun session on loppumassa? Kuten julkisissapalveluissa (Kela, OmaKanta, Suomi.fi yms)
108

9+
# Jokin sivu (esimerkiksi asetuksiin), joka näyttää kaikki aktiiviset (miksei epäaktiiviset) Sessionit. Myöskin Sessionin poistomahdollisuus voitaisiin lisätä
10+
11+
# Enter-näppäimellä EditModalin ja DeleteModalin hyväksyminen
12+
1113
### </IDEOITA>
1214

1315
TODO:

components/Modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createPortal } from 'react-dom';
33
import { twMerge } from 'tailwind-merge';
44
import { TitleText } from './TitleText';
55
import SvgXClose from '~/icons/x_close';
6-
import { useKeyPress } from '~/utils/hooks/useKeyPress';
6+
import { useKeyPress } from '~/hooks/useKeyPress';
77

88
export function Modal({
99
children,
File renamed without changes.

pages/api/cron/index.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { NextApiRequest, NextApiResponse } from 'next';
2+
import { lucia } from '~/backend/auth';
3+
import { handleError } from '~/backend/handleError';
4+
import { HttpError } from '~/backend/HttpError';
5+
6+
export default async function handler(
7+
req: NextApiRequest,
8+
res: NextApiResponse,
9+
) {
10+
try {
11+
if (req.method !== 'GET') {
12+
throw new HttpError('Invalid HTTP request method!', 405);
13+
}
14+
15+
const authHeader = req.headers.authorization;
16+
17+
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
18+
throw new HttpError('Unauthorized!', 401);
19+
}
20+
21+
// if authHeader was correct we can delete expired sessions
22+
23+
console.log('Cron job activated! Deleting expired sessions...');
24+
await lucia.deleteExpiredSessions();
25+
res.status(200).end();
26+
} catch (e) {
27+
return handleError(res, e);
28+
}
29+
}

utils/handleToasts.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ import { toast } from 'react-toastify';
22

33
export function handleErrorToast(errorText: string) {
44
try {
5-
const toastId = toast(errorText, {
5+
const toastId = `toast-${errorText}`;
6+
const toastExists = document.getElementById(toastId);
7+
8+
// if toast exists, reset timer
9+
if (toastExists) {
10+
toast.update(errorText, { progress: 0 });
11+
return;
12+
}
13+
14+
toast(errorText, {
615
type: 'error',
7-
toastId: window.crypto.randomUUID(),
16+
toastId: toastId,
817
});
918

1019
const observer = new MutationObserver(() => {
11-
const addedToast = document.getElementById(toastId.toString());
20+
const addedToast = document.getElementById(toastId);
1221
if (addedToast) {
1322
addedToast.addEventListener('mouseenter', () => {
1423
toast.update(toastId, { progress: 1 });

vercel.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"crons": [
3+
{
4+
"path": "/api/cron",
5+
"schedule": "0 0 * * *"
6+
}
7+
]
8+
}

0 commit comments

Comments
 (0)