Merge stable version before large change #16

Merged
xeovalyte merged 28 commits from dev into main 2023-02-14 15:37:45 +01:00
4 changed files with 16 additions and 16 deletions
Showing only changes of commit 388d989229 - Show all commits

View File

@ -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'})

View File

@ -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);

View File

@ -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) {

View File

@ -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()