Skip to content

Commit 37efc08

Browse files
realtime message feature added
1 parent dd0ab0a commit 37efc08

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

.github/workflows/preview.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ jobs:
3030
printf "%s" "$DOTENV" > .env
3131
printf "%s" "$DOTENV" > .env.production
3232
printf "%s" "$DOTENV" > .vercel/.env.production.local
33+
- name: Verify required env vars present
34+
run: |
35+
if grep -qE '^NEXT_PUBLIC_PUSHER_APP_KEY=' .env 2>/dev/null; then
36+
echo "Found NEXT_PUBLIC_PUSHER_APP_KEY in .env"
37+
exit 0
38+
fi
39+
echo "Missing NEXT_PUBLIC_PUSHER_APP_KEY in dotenv. Add it to the GitHub Environment secret PRODUCTION."
40+
exit 1
3341
- name: Install dependencies (legacy peer deps)
3442
run: npm ci --legacy-peer-deps
3543
- name: Build Project Artifacts

src/lib/pusher.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import PusherServer from "pusher";
22
import PusherClient from "pusher-js";
33

44
const CLUSTER = "ap1";
5+
const PUSHER_KEY = process.env.NEXT_PUBLIC_PUSHER_APP_KEY;
56

67
declare global {
78
var pusherServerInstance: PusherServer | undefined;
@@ -15,28 +16,29 @@ const globalForPusher = globalThis as typeof globalThis & {
1516

1617
if (typeof window === "undefined") {
1718
if (!globalForPusher.pusherServerInstance) {
18-
globalForPusher.pusherServerInstance = new PusherServer({
19-
appId: process.env.PUSHER_APP_ID!,
20-
key: process.env.NEXT_PUBLIC_PUSHER_APP_KEY!,
21-
secret: process.env.PUSHER_APP_SECRET!,
22-
cluster: CLUSTER,
23-
useTLS: true,
24-
});
19+
if (process.env.PUSHER_APP_ID && PUSHER_KEY && process.env.PUSHER_APP_SECRET) {
20+
globalForPusher.pusherServerInstance = new PusherServer({
21+
appId: process.env.PUSHER_APP_ID,
22+
key: PUSHER_KEY,
23+
secret: process.env.PUSHER_APP_SECRET,
24+
cluster: CLUSTER,
25+
useTLS: true,
26+
});
27+
}
2528
}
2629
}
2730

2831
if (typeof window !== "undefined") {
2932
if (!globalForPusher.pusherClientInstance) {
30-
globalForPusher.pusherClientInstance = new PusherClient(
31-
process.env.NEXT_PUBLIC_PUSHER_APP_KEY!,
32-
{
33+
if (PUSHER_KEY) {
34+
globalForPusher.pusherClientInstance = new PusherClient(PUSHER_KEY, {
3335
cluster: CLUSTER,
3436
channelAuthorization: {
3537
endpoint: "/api/pusher-auth",
3638
transport: "ajax",
3739
},
38-
}
39-
);
40+
});
41+
}
4042
}
4143
}
4244

tsconfig.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"compilerOptions": {
33
"target": "ES2017",
4-
"lib": ["dom", "dom.iterable", "esnext"],
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
59
"allowJs": true,
610
"skipLibCheck": true,
711
"strict": true,
@@ -11,17 +15,27 @@
1115
"moduleResolution": "bundler",
1216
"resolveJsonModule": true,
1317
"isolatedModules": true,
14-
"jsx": "preserve",
18+
"jsx": "react-jsx",
1519
"incremental": true,
1620
"plugins": [
1721
{
1822
"name": "next"
1923
}
2024
],
2125
"paths": {
22-
"@/*": ["./src/*"]
26+
"@/*": [
27+
"./src/*"
28+
]
2329
}
2430
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26-
"exclude": ["node_modules"]
31+
"include": [
32+
"next-env.d.ts",
33+
"**/*.ts",
34+
"**/*.tsx",
35+
".next/types/**/*.ts",
36+
".next/dev/types/**/*.ts"
37+
],
38+
"exclude": [
39+
"node_modules"
40+
]
2741
}

0 commit comments

Comments
 (0)