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,
},
});