Merge stable version before large change #16

Merged
xeovalyte merged 28 commits from dev into main 2023-02-14 15:37:45 +01:00
3 changed files with 30 additions and 21 deletions
Showing only changes of commit 9a5cf46400 - Show all commits

View File

@ -1,18 +1,24 @@
<template> <template>
<div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md"> <div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md">
<form @submit.prevent="sendNews" class="flex flex-col"> <form @submit.prevent="sendNews" class="flex flex-col">
<label class="font-bold">Titel</label> <label class="font-bold">Titel</label>
<input v-model="form.title" required="true" class="input mb-5" type="text"> <input v-model="form.title" required="true" class="input mb-5" type="text">
<label class="font-bold">Beschrijving</label> <label class="font-bold">Beschrijving</label>
<textarea v-model="form.description" required="true" class="input mb-5" /> <textarea v-model="form.description" required="true" class="input mb-5" />
<div class="w-full flex flex-wrap justify-between"> <label class="font-bold">Groep</label>
<input :disabled="disableButtons" type="submit" value="Stuur Bericht" class="btn w-full sm:w-40 mb-1"> <select v-model="form.topic" required="true" class="input mb-5">
<button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Annuleer</button> <option value="all">Iedereen</option>
</div> <option value="test">Test</option>
</form> </select>
</div>
<div class="w-full flex flex-wrap justify-between">
<input :disabled="disableButtons" type="submit" value="Stuur Bericht" class="btn w-full sm:w-40 mb-1">
<button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Annuleer</button>
</div>
</form>
</div>
</template> </template>
<script setup> <script setup>
@ -20,8 +26,8 @@ import { addDoc, collection, serverTimestamp, Timestamp } from 'firebase/firesto
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
definePageMeta({ definePageMeta({
title: 'Nieuw Bericht', title: 'Nieuw Bericht',
key: 'back' key: 'back'
}) })
const { news, db, auth } = inject('firebase') const { news, db, auth } = inject('firebase')
@ -31,8 +37,9 @@ const toast = useToast()
const disableButtons = ref(false) const disableButtons = ref(false)
const form = ref({ const form = ref({
title: '', title: '',
description: '', description: '',
topic: ''
}) })
const sendNews = async () => { const sendNews = async () => {
@ -44,7 +51,7 @@ const sendNews = async () => {
const { error } = await useFetch('/api/sendmessage', { const { error } = await useFetch('/api/sendmessage', {
method: 'post', method: 'post',
body: { title: form.value.title, body: form.value.description, token: idToken } body: { title: form.value.title, body: form.value.description, token: idToken, topic: form.value.topic }
}) })
if (error.value) { if (error.value) {

View File

@ -15,11 +15,11 @@
<h1 class="text-xl ml-2 font-bold"></h1> <h1 class="text-xl ml-2 font-bold"></h1>
<div class="container"> <div class="container">
<div class="item break-words "> <div class="item break-words ">
Registration Token: <b>{{ registrationToken }}</b> Registration Token: <b>{{ registrationToken }}</b>
</div> </div>
<div class="divider" /> <div class="divider" />
<div class="item break-words "> <div class="item break-words ">
User ID: <b>{{ userData.id }}</b> User ID: <b>{{ userData.id }}</b>
</div> </div>
</div> </div>
</div> </div>

View File

@ -3,11 +3,13 @@ import { getAuth } from 'firebase-admin/auth'
import { getMessaging } from 'firebase-admin/messaging' import { getMessaging } from 'firebase-admin/messaging'
export default defineEventHandler(async event => { export default defineEventHandler(async event => {
const { token, body, title } = await readBody(event); const { token, body, title, topic } = await readBody(event);
if (!token) throw createError({ statusCode: 400, statusMessage: 'no-token'}) if (!token) throw createError({ statusCode: 400, statusMessage: 'no-token'})
if (!body) throw createError({ statusCode: 400, statusMessage: 'no-body'}) if (!body) throw createError({ statusCode: 400, statusMessage: 'no-body'})
if (!title) throw createError({ statusCode: 400, statusMessage: 'no-title'}) if (!title) throw createError({ statusCode: 400, statusMessage: 'no-title'})
if (!topic) throw createError({ statusCode: 400, statusMessage: 'no-topic'})
let decodedToken = null; let decodedToken = null;
@ -42,7 +44,7 @@ export default defineEventHandler(async event => {
icon: '/ios/256.png' icon: '/ios/256.png'
} }
}, },
topic: 'test', topic: topic,
apns: { apns: {
payload: { payload: {
aps: { aps: {