Lapis
BABetter Auth
•Created by Felix on 4/10/2025 in #help
Session cookie not working in production deployment

142 replies
BABetter Auth
•Created by Felix on 4/10/2025 in #help
Session cookie not working in production deployment

142 replies
BABetter Auth
•Created by Felix on 4/10/2025 in #help
Session cookie not working in production deployment
For ex. you can include token in a call from expo to backend : const token = await SecureStore.getItemAsync('myapp-jwt');
const cookies = authClient.getCookie();
const opts: RequestInit = {
method,
headers: {
'Content-Type': 'application/json',
'x-client-type': 'mobile',
...(token ? { Authorization:
Bearer ${token}
} : {}),
Cookie: cookies || '',
},
credentials: 'include',
...(method === 'POST' && { body: JSON.stringify({ action, params }) }),
};
const res = await fetch(url, opts);
if (!res) throw new Error('Request failed');
return res.json();
}142 replies
BABetter Auth
•Created by Felix on 4/10/2025 in #help
Session cookie not working in production deployment
Now NextJs backend can authorize , get payload of user data using the token
142 replies
BABetter Auth
•Created by Felix on 4/10/2025 in #help
Session cookie not working in production deployment
You can now include this JWT token in your calls to backend.
142 replies
BABetter Auth
•Created by Felix on 4/10/2025 in #help
Session cookie not working in production deployment
what you can do is on succesfull login in Expo you can call a function like refresh session : const refreshSession = async () => {
try {
const session = await authClient.getSession();
const sessionToken = session?.data?.session?.token;
if (!sessionToken) {
await SecureStore.deleteItemAsync('myapp-jwt');
setUser(null);
setIsAuthenticated(false);
return;
}
const response = await fetch(
${BACKEND}/api/auth/token
, {
headers: {
Authorization: Bearer ${sessionToken}
,
},
});
const data = await response.json();
if (data.token) {
await SecureStore.setItemAsync('myapp-jwt', data.token);
} else {
await SecureStore.deleteItemAsync('myapp-jwt');
}142 replies
BABetter Auth
•Created by karlupo on 4/24/2025 in #help
Social signup for Expo App
This method is for only if you dont have your backend/domain deployed and you are working locally
12 replies
BABetter Auth
•Created by karlupo on 4/24/2025 in #help
Social signup for Expo App
the redirect URI here in auth.ts should be same as in your Google credential authorized redirect URI
12 replies
BABetter Auth
•Created by karlupo on 4/24/2025 in #help
Social signup for Expo App
You have to tunnel you local backend ip using Ngrok . You will have to use that given url in your auth.ts like },
socialProviders: {
google: {
clientId: process.env.AUTH_GOOGLE_ID,
clientSecret: process.env.AUTH_GOOGLE_SECRET,
redirectURI: "https://a652-103-182-161-102.ngrok-free.app/api/auth/callback/google",
},
},
emailAndPassword: {
enabled: true,
},
plugins: [
expo(),
jwt(),
bearer(),
oAuthProxy({ productionURL: "https://a652-103-182-161-102.ngrok-free.app" }),
openAPI(),
12 replies
BABetter Auth
•Created by karlupo on 4/24/2025 in #help
Social signup for Expo App
Okay so there is a bit workaround for this because in local development Google thorws error like private ip not allowed etc.
12 replies
BABetter Auth
•Created by karlupo on 4/24/2025 in #help
Social signup for Expo App
Are you using the token id method or redirect URI ?
12 replies
BABetter Auth
•Created by Pander on 2/19/2025 in #help
Retrieving session after magic link signin in Expo
auth.useSession() returning null on nextjs server right?
6 replies
BABetter Auth
•Created by Dominik on 4/19/2025 in #help
Expo plugin isn't a valid plugin
maybe try a different package manager
14 replies
BABetter Auth
•Created by Lapis on 2/14/2025 in #help
Hello! I have a specific question about session handling between Expo and Next.js using Better Auth.
@bekacru
7 replies
BABetter Auth
•Created by Lapis on 2/14/2025 in #help
Hello! I have a specific question about session handling between Expo and Next.js using Better Auth.
up
7 replies
BABetter Auth
•Created by Lapis on 2/14/2025 in #help
Hello! I have a specific question about session handling between Expo and Next.js using Better Auth.
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
7 replies
BABetter Auth
•Created by Lapis on 2/14/2025 in #help
Hello! I have a specific question about session handling between Expo and Next.js using Better Auth.
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
7 replies