Mobile notifications for iOS (#210)
* mobile: wire notification registration and listener
* implement backend components for push notifications
* refactor: agentic comment cleanup
* docs: use proper module name for particle processor
* set required env variables for push notifications
* bump version
* fix: always upsert push token on mobile start
* Revert "fix: always upsert push token on mobile start"
This reverts commit 90ff18a788.
* send push notifications regardless of online status
This commit was merged in pull request #210.
This commit is contained in:
@@ -7,6 +7,10 @@ import { apiClient } from "@/api/client";
|
||||
import type { Human } from "@/api/types";
|
||||
import { firebaseAuth } from "@/firebase";
|
||||
import { logError, ApiError } from "@/lib/errors";
|
||||
import {
|
||||
syncPushToken,
|
||||
unregisterPushToken,
|
||||
} from "@/lib/push-notifications";
|
||||
import { hydrateSession, useSessionStore } from "./session-store";
|
||||
|
||||
async function signInToFirebase(): Promise<void> {
|
||||
@@ -60,6 +64,7 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
const user = await apiClient.me();
|
||||
await signInToFirebase();
|
||||
set({ status: "authenticated", user });
|
||||
void syncPushToken();
|
||||
} catch (err) {
|
||||
// Expected on expired/invalid tokens — fall back to the login screen.
|
||||
logError(err, { scope: "auth.restore" });
|
||||
@@ -89,6 +94,7 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
await useSessionStore.getState().setToken(token);
|
||||
await signInToFirebase();
|
||||
set({ status: "authenticated", user: human });
|
||||
void syncPushToken();
|
||||
} catch (e) {
|
||||
const message = e instanceof ApiError ? e.message : "Failed to sign in";
|
||||
set({ error: message });
|
||||
@@ -100,6 +106,9 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
|
||||
signOut: async () => {
|
||||
set({ isSigningOut: true });
|
||||
// Unregister the push token first — once the session token is cleared the
|
||||
// backend call would 401. Best-effort: failures must not block sign-out.
|
||||
await unregisterPushToken();
|
||||
try {
|
||||
await apiClient.signOut();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user