WIP 1.51.14: people and messaging on v2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 17:02:26 +02:00
co-authored by Claude Opus 5.5
parent fdc3db8d23
commit e95d52ccdd
42 changed files with 9250 additions and 183 deletions
+7 -7
View File
@@ -1,13 +1,14 @@
"use client";
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
import { apiFetch, ApiError } from "@/lib/api";
import { ApiError } from "@/lib/api";
import { AuthResponse, AuthUser, TwoFactorChallenge, clearToken, getDeviceToken, getToken, saveDeviceToken, saveToken } from "@/lib/auth";
import { apiV2, type V2Result } from "@/lib/apiV2";
import { apiV2, type V2Result, apiV2Data } from "@/lib/apiV2";
// A v2 "signed_in" answer as the session the app keeps (the user's fields plus the token).
type V2Session = Extract<V2Result<"/auth/login", "post">["data"], { status: "signed_in" }>;
const toAuthResponse = (s: V2Session): AuthResponse => ({
/** A v2 sign-in answer as the app's AuthResponse (also used by the self-service kiosk). */
export const toAuthResponse = (s: V2Session): AuthResponse => ({
...s.user, token: s.token, newsPromptPending: s.newsPromptPending, noticePromptPending: s.noticePromptPending,
...(s.deviceToken ? { deviceToken: s.deviceToken } : {}),
});
@@ -58,7 +59,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
// Validate the stored token by fetching the user profile.
// Only update React state after a successful response so we never
// hold a half-initialised (token set, user null) state.
const me = await apiFetch<AuthUser>("/api/users/profile", { authToken: t });
const me = await (apiV2Data("get", "/me", { authToken: t }) as Promise<AuthUser>);
setToken(t);
setUser(me);
cacheUser(me);
@@ -117,10 +118,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
}, [startSession]);
const resendTwoFactor = useCallback((challengeId: string) => {
return apiFetch<TwoFactorChallenge>("/api/users/login/2fa/resend", {
method: "POST",
return (apiV2Data("post", "/auth/login/code/resend", {
body: { challengeId },
});
}) as Promise<TwoFactorChallenge>);
}, []);
const register = useCallback(async (data: { name: string; email: string; password: string; phoneNumber?: string; notificationPreference?: "email" | "whatsapp" | "both"; newsOptIn?: boolean }) => {