Hello! I have a specific question about session handling between Expo and Next.js using Better Auth.
My setup:
- Next.js web app with Better Auth
- Expo mobile app that authenticates through Better Auth
Everything works for authentication, but I need help with session handling.
Specifically:
In my Next.js app, this code works perfectly for web logins:
```typescript
const session = await auth.api.getSession({
headers: headersList,
});
return session?.user;
But when logging in from Expo, the session isn't recognized.
Question:
What's the correct way to ensure auth.api.getSession() can recognize and return the session for users logged in through the Expo app? Do I need to pass specific headers or use a particular configuration to make this work?
3 Replies
Current behavior:
1. Web login works perfectly - auth.api.getSession() returns the correct user session
2. Expo authentication works (can log in successfully)
3. BUT: When making API calls from Expo to Next.js backend, the currentUser function doesn't recognize the mobile user's session
How can I make auth.api.getSession() recognize the session when the request comes from my Expo app? Currently, it returns null for mobile users even though they're properly authenticated.
Additional context:
Using the expoClient plugin with SecureStore
Authentication flow works (can log in/out)
Just need the session to be recognized on the backend
up
@bekacru
I'm not sure if this is related, but there was an issue that was fixed in the latest release. If you haven't upgraded yet, please do so and let me know if the issue persists
@bekacru im getting same error now, with latest versions