Merge stable version before large change #16
@ -1,5 +1,4 @@
|
||||
import { db } from '../utils/firebase'
|
||||
import { getAuth } from 'firebase-admin/auth'
|
||||
import { db, auth } from '../utils/firebase'
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const { email, token } = await readBody(event);
|
||||
@ -8,7 +7,7 @@ export default defineEventHandler(async event => {
|
||||
if (!token) throw createError({ statusCode: 400, statusMessage: 'no-token'})
|
||||
|
||||
try {
|
||||
await getAuth().verifyIdToken(token)
|
||||
await auth.verifyIdToken(token)
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
throw createError({ statusCode: 500, statusMessage: 'error-verify-id'})
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { db } from '../utils/firebase'
|
||||
import { getAuth } from 'firebase-admin/auth'
|
||||
import { getMessaging } from 'firebase-admin/messaging'
|
||||
import { db, auth, messaging } from '../utils/firebase'
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const { token, body, title, topic } = await readBody(event);
|
||||
@ -14,7 +12,7 @@ export default defineEventHandler(async event => {
|
||||
let decodedToken = null;
|
||||
|
||||
try {
|
||||
decodedToken = await getAuth().verifyIdToken(token)
|
||||
decodedToken = await auth.verifyIdToken(token)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
throw createError({ statusCode: 500, statusMessage: 'error-verify-id'})
|
||||
@ -53,7 +51,7 @@ export default defineEventHandler(async event => {
|
||||
}
|
||||
}
|
||||
};
|
||||
const response = await getMessaging().send(message)
|
||||
const response = await messaging.send(message)
|
||||
|
||||
console.log('Successfully sent message:', response);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getMessaging } from 'firebase-admin/messaging'
|
||||
import { messaging } from '../utils/firebase'
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const { topic, registrationToken } = await readBody(event);
|
||||
@ -8,7 +8,7 @@ export default defineEventHandler(async event => {
|
||||
if (!registrationToken) throw createError({ statusCode: 400, statusMessage: 'no-registrationtoken'})
|
||||
|
||||
try {
|
||||
await getMessaging().subscribeToTopic([registrationToken], topic)
|
||||
await messaging.subscribeToTopic([registrationToken], topic)
|
||||
|
||||
return { code: 'success'}
|
||||
} catch (e) {
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
const admin = require("firebase-admin");
|
||||
|
||||
import { initializeApp, cert } from 'firebase-admin/app';
|
||||
import { getFirestore } from 'firebase-admin/firestore';
|
||||
import { getMessaging } from 'firebase-admin/messaging';
|
||||
import { getAuth } from 'firebase-admin/auth'
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
export const app = admin.initializeApp({
|
||||
credential: admin.credential.cert({
|
||||
console.log('testing', config)
|
||||
|
||||
export const app = initializeApp({
|
||||
credential: cert({
|
||||
"project_id": "wrbapp",
|
||||
"private_key_id": config.privateKeyId,
|
||||
"private_key": config.privateKey,
|
||||
@ -23,3 +24,5 @@ export const app = admin.initializeApp({
|
||||
export const firestore = getFirestore()
|
||||
|
||||
export const db = getFirestore();
|
||||
export const messaging = getMessaging();
|
||||
export const auth = getAuth()
|
||||
|
Loading…
Reference in New Issue
Block a user