21 lines
545 B
TypeScript
21 lines
545 B
TypeScript
export default defineNuxtPlugin(async () => {
|
|
const { token } = useAuth();
|
|
const anonymousClientId = useState<string | null>("anonymous-push-client-id", () => null);
|
|
const { syncServiceWorkerContext, syncNativeSubscription, isNativeApp } = usePush();
|
|
|
|
if (isNativeApp()) {
|
|
await syncNativeSubscription();
|
|
} else {
|
|
await syncServiceWorkerContext();
|
|
}
|
|
|
|
watch([token, anonymousClientId], () => {
|
|
if (isNativeApp()) {
|
|
void syncNativeSubscription();
|
|
return;
|
|
}
|
|
|
|
void syncServiceWorkerContext();
|
|
});
|
|
});
|