Update firebase config

This commit is contained in:
Made Baruna 2022-07-21 11:38:37 +07:00
parent edc036f62f
commit 1cd1e40c77
4 changed files with 34 additions and 24 deletions

View file

@ -46,23 +46,6 @@
});
window.localforage = localforage;
await checkLocalSave();
if ('serviceWorker' in navigator && import.meta.env.PROD) {
navigator.serviceWorker
.register('/service-worker.js', {
scope: 'firebase-cloud-messaging-push-scope',
})
.then(
function (registration) {
console.log('Service worker registration succeeded');
},
function (error) {
console.log('Service worker registration failed:', error);
},
);
} else {
console.log('Service workers are not supported.');
}
});
$: segment = $page.url.pathname.substring(1).split('/')[0];

View file

@ -75,10 +75,8 @@ async function getToken() {
console.log('request token');
try {
const swRegistration = await navigator.serviceWorker.getRegistration('/firebase-cloud-messaging-push-scope');
const token = await messaging.getToken({
vapidKey: 'BA6niiIWa_QP2SXMTjS8gBtM3M7m0q0n0_ZWjECw3Z_iEFujzPG2VdAAvNFJ5btbgpEiRe2B80M4QKxRSxtmvDw',
serviceWorkerRegistration: swRegistration,
});
if (token) {

View file

@ -1,11 +1,40 @@
import { resolve } from 'path';
import { sveltekit } from '@sveltejs/kit/vite';
import { build } from 'vite';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()],
/** @type {import('vite').Plugin} */
const firebaseSwPlugin = {
name: 'firebaseplugin',
apply: 'build',
enforce: 'post',
buildEnd: async () => {
const conf = {
build: {
sourcemap: true,
lib: {
entry: resolve(__dirname, 'src/firebase-messaging-sw.js'),
formats: ['es'],
},
rollupOptions: {
output: {
entryFileNames: 'firebase-messaging-sw.js',
},
},
outDir: resolve(__dirname, '.svelte-kit/output/client'),
emptyOutDir: false,
},
configFile: false,
};
await build(conf);
},
};
/** @type {import('vite').UserConfig} */
const config = {
build: {
sourcemap: true,
},
plugins: [sveltekit(), firebaseSwPlugin],
};
export default config;