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,
},
});
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?