Two ways to do authentication with Audius:
- Main app (Hedgehog): Email/password sign-in, sign-up flow, Hedgehog-based wallet/identity (see Source of truth below).
- Runnable Expo app (OAuth): Simple OAuth sign-in at audius.co; after sign-in you get the user’s profile and can use the SDK for authenticated GETs in your code. This folder contains the example.
Expo app: Sign in with Audius using the SDK’s OAuth (PKCE). Tokens are stored in AsyncStorage and the SDK automatically adds authorization headers to subsequent requests. No WebView or manual redirect handling.
- API key from audius.co/settings → Developer Apps
- Redirect URI registered for this example:
audiusauth://oauth/callback
From the apps repo root:
npm install
npm run build -w @audius/sdk
cd packages/mobile/examples/auth-sign-in
cp .env.example .env
# Edit .env: set EXPO_PUBLIC_AUDIUS_API_KEY to your API key
npm install
npx expo startPress i (iOS) or a (Android). Tap Sign in with Audius → complete login in the system browser (expo-web-browser) → you’ll see your profile and feed, and Sign out.
Or from repo root: npm run mobile:example:auth-sign-in (after npm install in the example dir once).
| File | Purpose |
|---|---|
src/sdk.ts |
getSDK() — single SDK instance with apiKey and redirectUri; OAuth tokens stored via AsyncStorage. |
App.tsx |
oauth.login(), oauth.getUser(), oauth.isAuthenticated(), oauth.logout(); feed and playback. |
Flow: oauth.login({ scope: 'read' }) opens the consent screen (expo-web-browser), completes PKCE, and stores tokens. Use getSDK() for all requests; the SDK adds auth headers when the user is signed in. See Log in with Audius.
Authentication, sign-in, login, sign-on, OAuth, authenticated gets, Hedgehog, identity service, authService, createAuthService, signIn, signOut, recovery.
- From repo root:
npm installthennpm run ios:devornpm run android:dev. - Open the app; the first screen is the sign-on flow (sign in or create account).
- To test sign-out: sign in, then use Settings (or profile) → Sign out.
No extra setup; the app uses staging identity by default (see packages/mobile/.env.dev).
| Concern | Location |
|---|---|
| Auth service (mobile) | packages/mobile/src/services/sdk/auth.ts – creates authService via createAuthService, wires localStorage, identity endpoint, key creation; exports authService, getAudiusWalletClient, solanaWalletService. |
| Sign-on UI (screens, stack) | packages/mobile/src/screens/sign-on-screen/ – SignOnStack.tsx, SignOnScreen, CreatePasswordScreen, PickHandleScreen, FinishProfileScreen, ConfirmEmailScreen, etc. |
| Auth service (shared API) | packages/common/src/services/auth/authService.ts – createAuthService, signIn(email, password, otp?), signOut, resetPassword, getWallet, confirmCredentials, changeCredentials. |
| Hedgehog / identity | packages/common/src/services/auth/hedgehog.ts, identity.ts – low-level Hedgehog instance and identity service integration. |
| Sign-in validation | packages/common/src/schemas/sign-on/signInSchema.ts – Zod schema for sign-in form. |
- Sign-in: User enters email/password →
authService.signIn()→ Hedgehoglogin()→ identity service → wallet stored; app navigates to main shell. - Sign-up: Multi-step flow (sign on → confirm email → create password → pick handle → finish profile / genres / artists) driven by
SignOnStackand sign-on redux/sagas. - Sign-out:
authService.signOut()(Hedgehoglogout()); UI returns to sign-on.
Auth is not third-party OAuth (e.g. Google/Meta); it is email/password + Hedgehog-managed wallet against the Audius identity service.