fix(mobile): address Apple review onboarding flows

This commit is contained in:
jjbrunton committed 2026-09-01 09:42:48 +01:00
1 parent 6883befff3
commit 7c8d91c89c
20 files changed
+661 -262

No files matched your search

@@ -0,0 +1,36 @@
import type { Profile } from '../types';
export interface AppleProfileNameSession {
userId: string;
accessToken: string;
}
export interface AppleProfileNamePersistenceDependencies {
getProfile: (accessToken: string) => Promise<{ profile: Pick<Profile, 'id' | 'name'> }>;
updateProfileName: (accessToken: string, name: string) => Promise<unknown>;
}
export type AppleProfileNamePersistenceResult = 'updated' | 'existing';
/**
* Persist a first-authorization Apple display name only for the exact subject
* and bearer that completed the authorization. The profile read protects an
* existing Sauci nickname from being overwritten.
*/
export async function persistAppleProfileName(
session: AppleProfileNameSession,
name: string,
dependencies: AppleProfileNamePersistenceDependencies,
): Promise<AppleProfileNamePersistenceResult> {
const { profile } = await dependencies.getProfile(session.accessToken);
if (profile.id !== session.userId) {
throw new Error('Apple profile subject did not match the authenticated user');
}
if (profile.name?.trim()) {
return 'existing';
}
await dependencies.updateProfileName(session.accessToken, name);
return 'updated';
}