瀏覽代碼

fix: 修改firebase

Before 9 月之前
父節點
當前提交
44288505a1

+ 3 - 0
messages/en.json

@@ -1071,5 +1071,8 @@
         "tails": []
       }
     ]
+  },
+  "titles": {
+    "home": "the home"
   }
 }

+ 4 - 0
messages/es.json

@@ -1071,5 +1071,9 @@
         "tails": []
       }
     ]
+  },
+  "titles": {
+    "home": "The home of over 30 million players",
+    "login": "Login"
   }
 }

+ 12 - 11
package.json

@@ -3,17 +3,17 @@
   "version": "0.1.0",
   "private": true,
   "scripts": {
-    "dev": "env-cmd -f .env.development next dev",
-    "dev:prod": "env-cmd -f .env.production next dev",
-    "build:prod": "env-cmd -f .env.production next build",
-    "start:prod": "env-cmd -f .env.production next start",
-    "dev:test": "env-cmd -f .env.test  next dev",
-    "build:test": "env-cmd -f .env.test next build",
-    "start:test": "env-cmd -f .env.test next start",
-    "dev:uat": "env-cmd -f .env.uat next dev",
-    "build:uat": "env-cmd -f .env.uat next build",
-    "start:uat": "env-cmd -f .env.uat next start",
-    "build": "env-cmd -f .env.production next build",
+    "dev": "env-cmd -f .env.development node scripts/swEnv.js && next dev",
+    "dev:prod": "env-cmd -f .env.production node scripts/swEnv.js && next dev",
+    "build:prod": "env-cmd -f .env.production node scripts/swEnv.js && next build",
+    "start:prod": "env-cmd -f .env.production node scripts/swEnv.js  &&next start",
+    "dev:test": "env-cmd -f .env.test node scripts/swEnv.js  && next dev",
+    "build:test": "env-cmd -f .env.test node scripts/swEnv.js && next build",
+    "start:test": "env-cmd -f .env.test node scripts/swEnv.js  &&next start",
+    "dev:uat": "env-cmd -f .env.uat next node scripts/swEnv.js && dev",
+    "build:uat": "env-cmd -f .env.uat next node scripts/swEnv.js  &&build",
+    "start:uat": "env-cmd -f .env.uat next node scripts/swEnv.js && start",
+    "build": "env-cmd -f .env.production node scripts/swEnv.js && next build",
     "lint": "next lint",
     "preinstall": "npx only-allow pnpm"
   },
@@ -43,6 +43,7 @@
     "@types/react": "^18.3.3",
     "@types/react-dom": "^18.3.0",
     "@types/webpack-env": "^1.18.5",
+    "dotenv": "^16.4.5",
     "eslint": "^8.57.0",
     "eslint-config-next": "14.2.4",
     "eslint-config-prettier": "^9.1.0",

+ 12 - 3
pnpm-lock.yaml

@@ -78,6 +78,9 @@ importers:
       '@types/webpack-env':
         specifier: ^1.18.5
         version: 1.18.5
+      dotenv:
+        specifier: ^16.4.5
+        version: 16.4.5
       eslint:
         specifier: ^8.57.0
         version: 8.57.0
@@ -917,6 +920,10 @@ packages:
     resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==}
     engines: {node: '>=6.0.0'}
 
+  dotenv@16.4.5:
+    resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==}
+    engines: {node: '>=12'}
+
   eastasianwidth@0.2.0:
     resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
 
@@ -3231,6 +3238,8 @@ snapshots:
     dependencies:
       esutils: 2.0.3
 
+  dotenv@16.4.5: {}
+
   eastasianwidth@0.2.0: {}
 
   emoji-regex@8.0.0: {}
@@ -3363,7 +3372,7 @@ snapshots:
       eslint: 8.57.0
       eslint-import-resolver-node: 0.3.9
       eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0)
-      eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
+      eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
       eslint-plugin-jsx-a11y: 6.9.0(eslint@8.57.0)
       eslint-plugin-react: 7.34.4(eslint@8.57.0)
       eslint-plugin-react-hooks: 4.6.2(eslint@8.57.0)
@@ -3391,7 +3400,7 @@ snapshots:
       enhanced-resolve: 5.17.0
       eslint: 8.57.0
       eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
-      eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
+      eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0)
       fast-glob: 3.3.2
       get-tsconfig: 4.7.5
       is-core-module: 2.14.0
@@ -3413,7 +3422,7 @@ snapshots:
     transitivePeerDependencies:
       - supports-color
 
-  eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0):
+  eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0):
     dependencies:
       array-includes: 3.1.8
       array.prototype.findlastindex: 1.2.5

+ 13 - 12
public/firebase-messaging-sw.js

@@ -1,12 +1,13 @@
 importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js');
 importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js');
-// if ('serviceWorker' in navigator) {
-//   navigator.serviceWorker.register('./firebase-messaging-sw.js').then(function (reg) {
-//     console.log('reg: ', reg.scope);
-//   }).catch(function (err) {
-//     console.log('err: ', err);
-//   })
-// }
+importScripts('swenv.js')
+if ('serviceWorker' in navigator) {
+  navigator.serviceWorker.register('./firebase-messaging-sw.js').then(function (reg) {
+    console.log('reg: ', reg.scope);
+  }).catch(function (err) {
+    console.log('err: ', err);
+  })
+}
 class CustomPushEvent extends Event {
   constructor(data) {
     super('push')
@@ -16,7 +17,6 @@ class CustomPushEvent extends Event {
   }
 }
 
-console.log(`🚀🚀🚀🚀🚀-> in firebase-messaging-sw.js on 19`,process);
 firebase.initializeApp({
   apiKey: process.env.NEXT_PUBLIC_FIREBASE_APIKEY,
   authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTHDOMAIN,
@@ -31,6 +31,7 @@ firebase.initializeApp({
 // messages.
 self.addEventListener('push', (e) => {
   // Skip if event is our own custom event
+  console.log(`🚀🚀🚀🚀🚀-> in firebase-messaging-sw.js on 41`, e);
   if (e.custom) return;
 
   // Kep old event data to override
@@ -68,8 +69,9 @@ messaging.onBackgroundMessage( (payload) => {
   const notificationTitle = payload.data.title;
   const notificationOptions = {
     body: payload.data.body,
-    icon: '/logo.png',
-    data: payload.data
+    icon: payload.data.image,
+    data: payload.data,
+   ...payload.data
   };
   return self.registration.showNotification(notificationTitle,
     notificationOptions);
@@ -78,7 +80,6 @@ messaging.onBackgroundMessage( (payload) => {
 self.onnotificationclick = function (event) {
   console.log(`🚀🚀🚀🚀🚀-> in firebase-messaging-sw.js on 91`,event);
   //example
-  const endpoint = event.notification.data.type;
-  self.clients.openWindow('/' + endpoint || "")
+  self.clients.openWindow('/')
   event.notification.close()
 }

+ 13 - 0
public/swenv.js

@@ -0,0 +1,13 @@
+
+  const process = {
+    env: {
+        NEXT_PUBLIC_FIREBASE_APIKEY: 'AIzaSyDAWORGKhdyzb5KeqTi535VmD5gN2Cdle8',
+        NEXT_PUBLIC_FIREBASE_AUTHDOMAIN: 'bcwin-a99b1.firebaseapp.com',
+        NEXT_PUBLIC_FIREBASE_PROJECTID: 'bcwin-a99b1',
+        NEXT_PUBLIC_FIREBASE_STORAGEBUCKET: 'bcwin-a99b1.appspot.com',
+        NEXT_PUBLIC_FIREBASE_MESSAGINGSENDERID: '1055413612814',
+        NEXT_PUBLIC_FIREBASE_APPID: '1:1055413612814:web:7a563237de8e43849d275f',
+        NEXT_PUBLIC_FIREBASE_MEASUREMENTID: 'G-467M2BYJMS',
+        NEXT_PUBLIC_FIREBASE_KEYS: 'BAOsT7kii-ctLzGrgXe_wYhfuxlme1v4njnD0uPSKp3DpSnrUa2e709b9dRaeYVU7jF_qIx1y9tEv0CvilDCdnM',
+    }
+}

+ 18 - 0
scripts/swEnv.js

@@ -0,0 +1,18 @@
+const fs = require("fs");
+fs.writeFileSync(
+    "./public/swenv.js",
+    `
+  const process = {
+    env: {
+        NEXT_PUBLIC_FIREBASE_APIKEY: '${process.env.NEXT_PUBLIC_FIREBASE_APIKEY}',
+        NEXT_PUBLIC_FIREBASE_AUTHDOMAIN: '${process.env.NEXT_PUBLIC_FIREBASE_AUTHDOMAIN}',
+        NEXT_PUBLIC_FIREBASE_PROJECTID: '${process.env.NEXT_PUBLIC_FIREBASE_PROJECTID}',
+        NEXT_PUBLIC_FIREBASE_STORAGEBUCKET: '${process.env.NEXT_PUBLIC_FIREBASE_STORAGEBUCKET}',
+        NEXT_PUBLIC_FIREBASE_MESSAGINGSENDERID: '${process.env.NEXT_PUBLIC_FIREBASE_MESSAGINGSENDERID}',
+        NEXT_PUBLIC_FIREBASE_APPID: '${process.env.NEXT_PUBLIC_FIREBASE_APPID}',
+        NEXT_PUBLIC_FIREBASE_MEASUREMENTID: '${process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENTID}',
+        NEXT_PUBLIC_FIREBASE_KEYS: '${process.env.NEXT_PUBLIC_FIREBASE_KEYS}',
+    }
+}
+`
+);

+ 6 - 1
src/app/[locale]/(enter)/login/layout.tsx

@@ -1,7 +1,12 @@
 import HeaderBack from "@/components/HeaderBack";
 import { getTranslations } from "next-intl/server";
 import { ReactNode } from "react";
-
+export const generateMetadata = async () => {
+    const t = await getTranslations("titles");
+    return {
+        title: t("login"),
+    };
+};
 export default async function Layout({
     children,
     params: { locale },

+ 8 - 4
src/app/[locale]/layout.tsx

@@ -1,5 +1,5 @@
 import clsx from "clsx";
-import { Viewport } from "next";
+import { Metadata, Viewport } from "next";
 import { NextIntlClientProvider } from "next-intl";
 import { getMessages } from "next-intl/server";
 import { Inter as FontSans } from "next/font/google";
@@ -14,9 +14,13 @@ const fontSans = FontSans({
 });
 export const viewport: Viewport = {};
 
-export const metadata = {
-    keywords: ["Next.js"],
-    description: "Next.js",
+export const metadata: Metadata = {
+    title: {
+        template: " %s | BCWin777",
+        default: "BCWin777",
+    },
+    keywords: ["BCWin777"],
+    description: "The home of over 30 million players",
     appleWebApp: {
         statusBarStyle: "black",
     },

+ 0 - 3
src/app/[locale]/providers.tsx

@@ -40,8 +40,6 @@ const initFirebase = () => {
         });
         return;
     }
-    console.log(`🚀🚀🚀🚀🚀-> in providers.tsx on 44`);
-
     //  是否开启通知
     // new Notification("这是标题", {
     //     body: "这是正文",
@@ -66,7 +64,6 @@ const initFirebase = () => {
     });
     const messaging = getMessaging(app);
     // 针对单机测试,或者服务端需要使用这个key可以放开
-    console.log(`🚀🚀🚀🚀🚀-> in providers.tsx on 68`);
     // if (process.env.NODE_ENV === "development") {
     getToken(messaging, {
         vapidKey: process.env.NEXT_PUBLIC_FIREBASE_KEYS,

+ 2 - 3
src/app/manifest.ts

@@ -2,9 +2,8 @@ import type { MetadataRoute } from "next";
 
 export default function manifest(): MetadataRoute.Manifest {
     return {
-        name: "BCWIN",
-        short_name: "BCWIN",
-        description: "BCWIN",
+        name: "BCWin777",
+        description: "BCWin777 The home of over 30 million players",
         start_url: "/",
         display: "standalone",
         background_color: "#ffffff",