Files
musicshare/apps/mobile/src/lib/connect.ts
T
chrisandClaude Opus 5.5 3568b71e90 Mobile: redesign, onboarding, QR codes, logo, Spotify setup
- Redesign matching the web: album-art backdrops, Reanimated equalizer,
  spinning live ring, drifting ambient background, gradient buttons with
  spring press feedback and haptics, Space Grotesk headings, animated feed
  (enter + layout transitions); fix invisible tab labels
- Four-step onboarding for new accounts: which app you listen with (sets
  where songs open), the matching share setup, find friends (search,
  scan, invite), and a featured song. Skippable; stored server-side
- QR codes: My code (share link) and an in-app scanner (camera only, no
  microphone permission)
- Spotify setup via Last.fm or ListenBrainz with guided linking; Android
  shares Spotify automatically through the phone reader
- New logo as app icon, adaptive/monochrome icon and splash
- app.config.ts allows cleartext only for local http:// test builds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzFywujuH9TiuXbr9vjoX8
2026-10-05 19:16:40 -04:00

28 lines
1.2 KiB
TypeScript

import * as Linking from 'expo-linking';
import * as WebBrowser from 'expo-web-browser';
import { SPOTIFY_LINK_PAGES } from '@musicshare/shared';
import { api } from './api';
export type SignInResult = 'connected' | 'cancelled';
export class SignInError extends Error {}
/**
* Sign in on the service's own site in an auth browser and come back through
* the app's deep link.
*/
export async function signInWithService(provider: 'plex' | 'lastfm'): Promise<SignInResult> {
// In Expo Go this is an exp:// URL, in builds musicshare://
const returnTo = Linking.createURL('settings');
const { url } = await api.authorizeUrl(provider, { client: 'mobile', returnTo });
const result = await WebBrowser.openAuthSessionAsync(url, returnTo);
if (result.type !== 'success') return 'cancelled';
const error = Linking.parse(result.url).queryParams?.error;
if (typeof error === 'string') throw new SignInError(error);
return 'connected';
}
/** Where users approve "Spotify Scrobbling" (Last.fm) or the Spotify link (ListenBrainz). */
export const openSpotifyLinkPage = (on: keyof typeof SPOTIFY_LINK_PAGES = 'lastfm') =>
WebBrowser.openBrowserAsync(SPOTIFY_LINK_PAGES[on]);