feat: integrate OneSignal for push notifications#167
Conversation
There was a problem hiding this comment.
Pull request overview
This PR integrates OneSignal web push notifications into the Next.js app by adding a client-side initialization component, registering the required service worker, and wiring the init into the root layout.
Changes:
- Add a
OneSignalInitclient component that initializes OneSignal usingNEXT_PUBLIC_ONESIGNAL_APP_ID. - Render
OneSignalInitfromsrc/app/layout.tsxso it runs globally. - Add
public/OneSignalSDKWorker.js,react-onesignaldependency, and introduce.env.example(plus a small.gitignoreupdate).
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/components/one-signal-init.tsx |
New client component to initialize OneSignal on mount. |
src/app/layout.tsx |
Mounts OneSignalInit in the root layout. |
public/OneSignalSDKWorker.js |
Adds OneSignal service worker loader via importScripts. |
package.json |
Adds react-onesignal dependency. |
package-lock.json |
Locks react-onesignal dependency version/resolution. |
.gitignore |
Ignores .idea/ and ensures .env.example remains tracked. |
.env.example |
Adds example env var placeholder for OneSignal App ID. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const appId = process.env.NEXT_PUBLIC_ONESIGNAL_APP_ID; | ||
|
|
||
| if (appId === undefined) { | ||
| console.error("OneSignal app ID is not defined, skipping initialization"); |
There was a problem hiding this comment.
NEXT_PUBLIC_ONESIGNAL_APP_ID can be defined but empty (e.g., .env.example sets it to an empty value). In that case this code will still call OneSignal.init with an empty appId and then log an initialization failure. Treat empty/whitespace values as “not configured” and skip initialization (e.g., validate it’s a non-empty string) to avoid noisy errors/misleading behavior.
| const appId = process.env.NEXT_PUBLIC_ONESIGNAL_APP_ID; | |
| if (appId === undefined) { | |
| console.error("OneSignal app ID is not defined, skipping initialization"); | |
| const rawAppId = process.env.NEXT_PUBLIC_ONESIGNAL_APP_ID; | |
| const appId = typeof rawAppId === "string" ? rawAppId.trim() : undefined; | |
| if (!appId) { | |
| console.error("OneSignal app ID is not defined or empty, skipping initialization"); |
| @@ -0,0 +1 @@ | |||
| NEXT_PUBLIC_ONESIGNAL_APP_ID= No newline at end of file | |||
There was a problem hiding this comment.
This example env file only includes NEXT_PUBLIC_ONESIGNAL_APP_ID, but the app also reads other env vars (e.g. FEEDBACK_FORM_URL, API_URL, JUWE_*_URL). To keep onboarding/docs accurate, include the full set of supported env vars here (or rename/scope this file if it’s intentionally OneSignal-only) and update the README section that currently instructs creating an .env with only FEEDBACK_FORM_URL.
| NEXT_PUBLIC_ONESIGNAL_APP_ID= | |
| # OneSignal configuration | |
| NEXT_PUBLIC_ONESIGNAL_APP_ID= | |
| # Feedback form configuration | |
| FEEDBACK_FORM_URL= | |
| # Backend API base URL | |
| API_URL= | |
| # JUWE-related service URLs | |
| # Add all JUWE_*_URL variables required by your deployment, for example: | |
| # JUWE_PORTAL_URL= | |
| # JUWE_ADMIN_URL= | |
| # JUWE_API_URL= |
No description provided.