Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

fix: notifications

Nikolai Giman32a2819ebf80
diff --git a/api/package.json b/api/package.json
index f34b399..2d9ce15 100644
--- a/api/package.json
+++ b/api/package.json
@@ -1,6 +1,6 @@
{
"name": "taskview-ce-api-server",
- "version": "1.42.2",
+ "version": "1.42.3",
"scripts": {
"dev": "bun run --watch ./server.ts",
"start": "NODE_ENV=production node ./dist/taskview-server.js",
diff --git a/api/src/tv-modules/notifications/repositories/DeviceTokensRepository.ts b/api/src/tv-modules/notifications/repositories/DeviceTokensRepository.ts
index 598dd8f..6b58e11 100644
--- a/api/src/tv-modules/notifications/repositories/DeviceTokensRepository.ts
+++ b/api/src/tv-modules/notifications/repositories/DeviceTokensRepository.ts
@@ -1,4 +1,4 @@
-import { and, eq } from 'drizzle-orm';
+import { and, eq, ne } from 'drizzle-orm';
import { DeviceTokensSchema, type DeviceTokensSchemaTypeForSelect } from 'taskview-db-schemas';
import { Database } from '../../../modules/db';
import { callWithCatch } from '../../../utils/helpers';
@@ -11,6 +11,14 @@ export class DeviceTokensRepository {
}
async register(userId: number, token: string, platform: string, timezone: string): Promise<boolean> {
+ await callWithCatch(() =>
+ this.db.dbDrizzle.delete(DeviceTokensSchema)
+ .where(and(
+ eq(DeviceTokensSchema.token, token),
+ ne(DeviceTokensSchema.userId, userId),
+ ))
+ );
+
const result = await callWithCatch(() =>
this.db.dbDrizzle.insert(DeviceTokensSchema).values({
userId,
diff --git a/package.json b/package.json
index 5ac213e..3441f1e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "taskview-ce-monorepo",
- "version": "1.42.2",
+ "version": "1.42.3",
"private": true,
"description": "TaskView CE monorepo containing web, API, and packages",
"workspaces": [
diff --git a/web/package.json b/web/package.json
index c14a262..947561e 100644
--- a/web/package.json
+++ b/web/package.json
@@ -2,7 +2,7 @@
"name": "web-nuxt-ui",
"private": true,
"type": "module",
- "version": "1.42.2",
+ "version": "1.42.3",
"scripts": {
"dev": "vite",
"build:packages": "pnpm --filter taskview-db-schemas build && pnpm --filter taskview-api build",
diff --git a/web/src/composables/useLogout.ts b/web/src/composables/useLogout.ts
index 08bee81..b7cce0e 100644
--- a/web/src/composables/useLogout.ts
+++ b/web/src/composables/useLogout.ts
@@ -1,12 +1,23 @@
import $api from '@/helpers/axios'
-import { $ls } from '@/plugins/axios'
+import { $ls, $tvApi } from '@/plugins/axios'
+import { usePushNotifications } from '@/composables/usePushNotifications'
export async function useLogout() {
+ const { getCurrentToken, reset } = usePushNotifications()
+
+ const deviceToken = getCurrentToken()
+ if (deviceToken) {
+ await $tvApi.notifications.unregisterDevice(deviceToken).catch((err) => {
+ console.error('[Logout] Failed to unregister device token:', err)
+ })
+ }
+
const result = await $api.post<{ logout: boolean }>('/module/auth/logout').catch((err) => {
console.error(err, $api)
})
if (result) {
+ reset()
await $ls.invalidateTokens()
return true
}
diff --git a/web/src/composables/usePushNotifications.ts b/web/src/composables/usePushNotifications.ts
index 6717920..041c861 100644
--- a/web/src/composables/usePushNotifications.ts
+++ b/web/src/composables/usePushNotifications.ts
@@ -9,6 +9,7 @@ import { ALL_TASKS_LIST_ID } from 'taskview-api'
const registered = ref(false)
let initialized = false
+let currentToken: string | null = null
export function usePushNotifications() {
const supported = Capacitor.isNativePlatform()
@@ -19,18 +20,22 @@ export function usePushNotifications() {
if (initialized || !supported) return
initialized = true
+ await FirebaseMessaging.removeAllListeners()
+
const permission = await FirebaseMessaging.requestPermissions()
if (permission.receive !== 'granted') return
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
const { token } = await FirebaseMessaging.getToken()
if (token) {
+ currentToken = token
const platform = Capacitor.getPlatform() as 'android' | 'ios'
await $tvApi.notifications.registerDevice(token, platform, timezone)
registered.value = true
}
FirebaseMessaging.addListener('tokenReceived', async ({ token }) => {
+ currentToken = token
const platform = Capacitor.getPlatform() as 'android' | 'ios'
await $tvApi.notifications.registerDevice(token, platform, timezone)
registered.value = true
@@ -64,5 +69,15 @@ export function usePushNotifications() {
})
}
- return { supported, registered, init }
+ function reset() {
+ initialized = false
+ registered.value = false
+ currentToken = null
+ }
+
+ function getCurrentToken() {
+ return currentToken
+ }
+
+ return { supported, registered, init, reset, getCurrentToken }
}
diff --git a/web/src/layouts/UserLayout.vue b/web/src/layouts/UserLayout.vue
index 69cad20..f72064a 100644
--- a/web/src/layouts/UserLayout.vue
+++ b/web/src/layouts/UserLayout.vue
@@ -95,6 +95,8 @@ App.addListener('appStateChange', async ({ isActive }) => {
} finally {
updateInProgress = false
}
+
+ initPush()
}
})