Determine if new user without callbacks in expo

When using authClient.signin.social in an expo app the deep link callbacks don't currently work, sounds like it should be fixed in an upcoming version. In the meantime I'm using the workaround that is in the example expo project to force a redirect after authenticating:
useEffect(() => {
if (isAuthenticated) {
if (navContainerRef.isReady()) {
router.push("/root");
}
}
}, [isAuthenticated, navContainerRef.isReady()]);
useEffect(() => {
if (isAuthenticated) {
if (navContainerRef.isReady()) {
router.push("/root");
}
}
}, [isAuthenticated, navContainerRef.isReady()]);
Until the new user callback is an option, is there an easy way to handle dealing with new users? I'm trying to avoid adding fields to the db just for this purpose (ex: newAccountSetupCompletedAt which defaults to null), but it's seeming like the most reasonable approach right now. Are there any better options?
4 Replies
KiNFiSH
KiNFiSH2w ago
for newUserCallback , you can use this -
const result = await authClient.signIn.social({
provider: "google",
callbackURL: "/dashboard",
newUserCallbackURL: "/new-user-link",
});
const result = await authClient.signIn.social({
provider: "google",
callbackURL: "/dashboard",
newUserCallbackURL: "/new-user-link",
});
how are u passing the link forcallbacks ? since better auth will do the deep link for you
trite
triteOP2w ago
const res = await authClient.signIn.social({
provider: 'google',
callbackURL: '/root',
});
const res = await authClient.signIn.social({
provider: 'google',
callbackURL: '/root',
});
I have another thread from last week that was asking about the callbacks not working (https://discord.com/channels/1288403910284935179/1355677792494288946), seems like it should be fixed at some point in the future, but for now it doesn't work. The useEffect block in the opening message for this thread is the workaround I'm using. Found it in the example here: https://github.com/better-auth/better-auth/blob/main/examples/expo-example/src/app/index.tsx#L18-L24
KiNFiSH
KiNFiSH2w ago
can u give me ur expo client auth config if possible .. i have seen this issue somewhere and also backend config if possible
trite
triteOP2w ago
import { createAuthClient } from 'better-auth/react';
import { expoClient } from '@better-auth/expo/client';
import * as SecureStore from 'expo-secure-store';
import { inferAdditionalFields } from 'better-auth/client/plugins';
import type { Auth } from '@/lib/auth';

export const authClient = createAuthClient({
// for local dev: EXPO_PUBLIC_MYAPP_API_URL=http://localhost:3000
baseURL: `${process.env.EXPO_PUBLIC_MYAPP_API_URL}/api/auth`,
plugins: [
expoClient({
scheme: 'myapp',
storagePrefix: 'myapp',
storage: SecureStore,
}),
inferAdditionalFields<Auth>({
user: {
name: { type: 'string', nullable: true },
firstName: { type: 'string', nullable: true },
lastName: { type: 'string', nullable: true },
email: { type: 'string', nullable: false },
phone: { type: 'string', nullable: true },
createdAt: { type: 'date', nullable: false },
updatedAt: { type: 'date', nullable: false },
},
}),
],
});
import { createAuthClient } from 'better-auth/react';
import { expoClient } from '@better-auth/expo/client';
import * as SecureStore from 'expo-secure-store';
import { inferAdditionalFields } from 'better-auth/client/plugins';
import type { Auth } from '@/lib/auth';

export const authClient = createAuthClient({
// for local dev: EXPO_PUBLIC_MYAPP_API_URL=http://localhost:3000
baseURL: `${process.env.EXPO_PUBLIC_MYAPP_API_URL}/api/auth`,
plugins: [
expoClient({
scheme: 'myapp',
storagePrefix: 'myapp',
storage: SecureStore,
}),
inferAdditionalFields<Auth>({
user: {
name: { type: 'string', nullable: true },
firstName: { type: 'string', nullable: true },
lastName: { type: 'string', nullable: true },
email: { type: 'string', nullable: false },
phone: { type: 'string', nullable: true },
createdAt: { type: 'date', nullable: false },
updatedAt: { type: 'date', nullable: false },
},
}),
],
});
Sorry for the delay, here's the config ^

Did you find this page helpful?