Issue with Account Overwriting When Using EXPO

After creating three projects on my computer, I logged in using Naver OAuth on two mobile devices. Each of these two projects is an individual EXPO app. One of them also has a backend server built with Express. Here’s the issue: After logging in with Naver account A, if I try logging in again with a different Naver account B, the app still logs me in as account A. Upon checking the database, there is no record of account B — it doesn’t exist. What’s even more confusing is that when I log the output from the mapProfileToUser function, it clearly shows the profile data for account B! How is this even possible? I've attached my auth configuration file below for your review.
import { betterAuth } from 'better-auth';
import { genericOAuth } from 'better-auth/plugins';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { PrismaClient } from '@prisma/client';
import { expo } from '@better-auth/expo';
const prisma = new PrismaClient();

const trustedOrigins = [
'http://localhost:3000',
'firstmyapp://*',
'exp://192.168.219.100:8081/--/',
'exp://192.168.219.100:8082/--/',
'exp://192.168.219.100:8081/--/(tabs)/today',
'exp://192.168.219.100:8082/--/(tabs)/today',
'exp://192.168.219.100:8081/--/(auth)/login_test',
'exp://192.168.219.100:8081/--/(test)/test',
];

export const auth = betterAuth({
baseURL: process.env.BASE_URL,
trustedOrigins,
database: prismaAdapter(prisma, {
provider: 'postgresql',
}),

user: {
deleteUser: {
enabled: true,
},
},
secret: process.env.BETTER_AUTH_SECRET,
account: {
accountLinking: {
enabled: true,
trustedProviders: ['naver', 'kakao', 'google'],
},
},
plugins: [
expo(),
genericOAuth({
config: [
{
providerId: 'naver',
authorizationUrl: 'https://nid.naver.com/oauth2.0/authorize',
tokenUrl: 'https://nid.naver.com/oauth2.0/token',
clientId: 'xxx',
clientSecret: 'xxx',
userInfoUrl: 'https://openapi.naver.com/v1/nid/me',
mapProfileToUser: (profile) => {
console.log('naver profile', profile);
return {
id: profile.response.id,
name: profile.response.name,
email: profile.response.email,
imageUrl: profile.response.profile_image,
nickname: profile.response.nickname,
};
},
// discoveryUrl: "https://openapi.naver.com/v1/nid/me",
},
{
providerId: 'kakao',
authorizationUrl: 'https://kauth.kakao.com/oauth/authorize',
tokenUrl: 'https://kauth.kakao.com/oauth/token',
userInfoUrl: 'https://kapi.kakao.com/v2/user/me',
clientId: 'xxx',
clientSecret: 'xxx',
mapProfileToUser: (profile) => {
return {
id: profile.id,
name: profile.properties.nickname,
email: profile.kakao_account.email,
};
},
},
],
}),
],
emailAndPassword: {
enabled: true,
disableSignUp: false,
},
});
import { betterAuth } from 'better-auth';
import { genericOAuth } from 'better-auth/plugins';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { PrismaClient } from '@prisma/client';
import { expo } from '@better-auth/expo';
const prisma = new PrismaClient();

const trustedOrigins = [
'http://localhost:3000',
'firstmyapp://*',
'exp://192.168.219.100:8081/--/',
'exp://192.168.219.100:8082/--/',
'exp://192.168.219.100:8081/--/(tabs)/today',
'exp://192.168.219.100:8082/--/(tabs)/today',
'exp://192.168.219.100:8081/--/(auth)/login_test',
'exp://192.168.219.100:8081/--/(test)/test',
];

export const auth = betterAuth({
baseURL: process.env.BASE_URL,
trustedOrigins,
database: prismaAdapter(prisma, {
provider: 'postgresql',
}),

user: {
deleteUser: {
enabled: true,
},
},
secret: process.env.BETTER_AUTH_SECRET,
account: {
accountLinking: {
enabled: true,
trustedProviders: ['naver', 'kakao', 'google'],
},
},
plugins: [
expo(),
genericOAuth({
config: [
{
providerId: 'naver',
authorizationUrl: 'https://nid.naver.com/oauth2.0/authorize',
tokenUrl: 'https://nid.naver.com/oauth2.0/token',
clientId: 'xxx',
clientSecret: 'xxx',
userInfoUrl: 'https://openapi.naver.com/v1/nid/me',
mapProfileToUser: (profile) => {
console.log('naver profile', profile);
return {
id: profile.response.id,
name: profile.response.name,
email: profile.response.email,
imageUrl: profile.response.profile_image,
nickname: profile.response.nickname,
};
},
// discoveryUrl: "https://openapi.naver.com/v1/nid/me",
},
{
providerId: 'kakao',
authorizationUrl: 'https://kauth.kakao.com/oauth/authorize',
tokenUrl: 'https://kauth.kakao.com/oauth/token',
userInfoUrl: 'https://kapi.kakao.com/v2/user/me',
clientId: 'xxx',
clientSecret: 'xxx',
mapProfileToUser: (profile) => {
return {
id: profile.id,
name: profile.properties.nickname,
email: profile.kakao_account.email,
};
},
},
],
}),
],
emailAndPassword: {
enabled: true,
disableSignUp: false,
},
});
5 Replies
뽀삐2
뽀삐2OP3mo ago
hello?
Robi
Robi3mo ago
Heyo , your setup seems to be pretty complex, could you link a minimal reproduction repo so i can see whats up locally and check if its something from better-auth's end ? 🙏🏼
뽀삐2
뽀삐2OP3mo ago
The bug has been resolved. However, it seems that when using Prisma, a different bug still occurs. For example, if I log in with the account a@naver.com while using Prisma, and then try to log in with another account like b@naver.com, the session still logs me in as a@naver.com. This issue persists regardless of the device used. Although the mapProfileToUser function shows logs as if a different account is being logged in, in reality, the login does not change. It appears this bug only occurs when Prisma is involved. --- It appears in oauth login i just pr
Robi
Robi3mo ago
Prisma with oauth with the same expo setup ?
뽀삐2
뽀삐2OP3mo ago
yes

Did you find this page helpful?