feat: auto-subscribe push on login, better push logging
- Auto-subscribe to push on login, register, and session restore - Guard against nil db in SendChannelNotification - Log push send count per channel message - Bump SW cache to v5
This commit is contained in:
@@ -71,6 +71,16 @@ interface AuthState {
|
||||
clearError: () => void;
|
||||
}
|
||||
|
||||
// ponytail: auto-subscribe to push notifications on auth
|
||||
function autoSubscribePush() {
|
||||
import("../stores/push.ts").then(({ usePushStore }) => {
|
||||
const ps = usePushStore.getState();
|
||||
if (ps.isSupported && Notification.permission !== 'denied' && !ps.isSubscribed) {
|
||||
ps.subscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>((set) => ({
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
@@ -86,6 +96,7 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
});
|
||||
const user = await api.get<User>("/auth/me");
|
||||
set({ user, isAuthenticated: true, isLoading: false });
|
||||
autoSubscribePush();
|
||||
} catch (error) {
|
||||
set({
|
||||
isLoading: false,
|
||||
@@ -106,6 +117,7 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
});
|
||||
const user = await api.get<User>("/auth/me");
|
||||
set({ user, isAuthenticated: true, isLoading: false });
|
||||
autoSubscribePush();
|
||||
} catch (error) {
|
||||
set({
|
||||
isLoading: false,
|
||||
@@ -135,6 +147,7 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
try {
|
||||
const user = await api.get<User>(`/auth/me?t=${Date.now()}`);
|
||||
set({ user, isAuthenticated: true, isLoading: false });
|
||||
autoSubscribePush();
|
||||
} catch (error) {
|
||||
set({
|
||||
user: null,
|
||||
|
||||
Reference in New Issue
Block a user