Repository navigation
Conversation
Better Auth expo client with SecureStore, device identity (install id + secret), anonymous, device-secret relaunch, email OTP linking and native Google flows, behind a Developer Menu screen. Local only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
Proof of concept: do not merge. This draft shows how AvyApp would sign in Members against AvyWeb (ADR 026 in the web repo), so the team can review the approach and try it locally. Nothing user-facing changes: it's one hidden screen under the Developer Menu. The server half is NWACus/web#1501.
Summary
AvyApp becomes a Better Auth client of AvyWeb's apex (
avy-fx.org/api/auth/*) through@better-auth/expo:installIdplus a random secret, both in SecureStore; the server stores only a hash of the secret).avy.session_tokencookie in SecureStore and sends it on every request. The rolling session lasts 60 days.sequenceDiagram participant App as AvyApp participant Apex as AvyWeb apex /api/auth App->>Apex: A: POST /sign-in/anonymous App->>Apex: POST /device/register {installId, secret} Note over App: session lost App->>Apex: B: POST /sign-in/device {installId, secret} Apex-->>App: same Anonymous Member, new session App->>Apex: C: email code (or D: Google idToken) with the anonymous session Apex-->>App: Linked Member (device, subscriptions and memberships moved)network/memberAuth.tscomponents/screens/main/MemberAuthDebug.tsxclientContext.tsavyWebHost(prodhttps://avy-fx.org, staginghttps://dev.avy-fx.org)app.config.tsGOOGLE_IOS_URL_SCHEMEis setGotchas the POC turned up, now handled in the code:
expoClientmust usecookiePrefix: 'avy'to match the server. Otherwise it silently never stores the session.expo-origin: avy://, and the server must listavy://intrustedOrigins. Otherwise every POST that carries a cookie returns 403INVALID_ORIGIN.expoClientsends no cookie on GoogleidTokensign-ins, so the app attaches the anonymous session itself. Without that, Google wouldn't link the anonymous Member. This path is untested.Stacked on #1269 — Docs updates for local development and debugging, so the diff only shows the POC commit.
Screenshots
Testing
Tested on the iOS simulator against a local AvyWeb. Android and Google were not tested.
1. Run AvyWeb locally
Follow the setup in NWACus/web#1501 (branch
busbyk/avyapp-better-auth-members,pnpm seed,pnpm dev,MEMBER_AUTH_RATE_LIMIT=false). Nothing is deployed yet:avy-fx.organddev.avy-fx.orgboth return 404 for/api/auth.2. Build the app
yarn install..env, setEXPO_PUBLIC_AVY_WEB_HOST=http://localhost:3000. You can also type the host on the screen.npx expo prebuild --clean && npx expo run:ios. A new dev build is required because this adds native modules (expo-secure-store,expo-crypto,@react-native-google-signin/google-signin). Expo Go and older dev builds will crash on the screen.adb reverse tcp:3000 tcp:3000solocalhost:3000reaches your machine, thennpx expo run:android.3. Walk the flows
/get-sessionshowsuser.isAnonymous: true, and Install id is filled in. In the web admin, Members has a new anonymous Member and Devices has a Device owned by it.device, with the same Member id and a new session. (A real app restart keeps the cookie, so B just returnssession.)isAnonymous: falseand a different Member id. In the admin, the anonymous Member is gone and the Device now belongs to the linked Member.linked: the device secret no longer signs in, so the app would show sign-in options./get-sessionisnull. The Device stays registered.D: sign in with Google needs OAuth clients that don't exist yet: iOS, Android and preview-Android clients, plus
EXPO_PUBLIC_GOOGLE_WEB_CLIENT_ID,EXPO_PUBLIC_GOOGLE_IOS_CLIENT_IDandGOOGLE_IOS_URL_SCHEMEin the app, and the matching ids on the server. Expect it to fail until those exist.Request Member deletion emails a confirmation link, so it needs SMTP configured on the web side.
app.json, or Expo/RN version changed🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.